android Wikipedia api game

2019-01-27 10:20发布

问题:

Hi i have to make an app with the following requirement:

When the user opens the app, it displays the text from a random Wikipedia page. 
(You’re free to use any logic for grabbing text from a random Wiki 
page(preferably using REST APIs)) The game requires a minimum of 10 lines of 
text on the screen. However, we want to show complete paragraphs of text to 
make it easier to understand the content displayed. Use the least number of 
paragraphs required to cross the 10 sentence limit.

I am able to get text from random wiki page but many times text is less than 10 sentences and to ensure minimum 10 sentences i used this url:

http://en.wikipedia.org/w/api.php?action=query&prop=extracts&format=json&exintro=&generator=random&exsentences=10

But this url is also not working as expected.

How do i approach this problem any suggestions will help.

回答1:

There are two things I notice in your query. First, the exintro means you only get sentences from over the first heading. Only a few articles have ten sentences before that. Second, you are getting results from all namespaces. By using grnnamespace=0 you will only get articles. So something like this might work for you:

https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&generator=random&exsentences=10&grnnamespace=0