Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
686 views
in Technique[技术] by (71.8m points)

java - android Wikipedia api game

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...