android 维基百科 api 游戏

android Wikipedia api game

嗨,我必须制作一个具有以下要求的应用程序:

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.

我能够从随机维基页面获取文本,但很多时候文本少于 10 个句子,为了确保最少 10 个句子,我使用了这个 url:

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

但是这个 url 也没有按预期工作。

我该如何解决这个问题,任何建议都会有所帮助。

我在您的查询中注意到两件事。首先,exintro 意味着您只能从第一个标题中获取句子。只有少数文章在此之前有十句话。其次,您正在从所有名称空间中获取结果。通过使用 grnnamespace=0,您将只会获得文章。所以这样的事情可能对你有用:

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