我需要一个 java 代码来使用 wikipedia api。我想获取维基百科上特定值的标签(出现在页面末尾的标签)。我知道我需要的api调用是
"http://en.wikipedia.org/w/api.php?action=query&format=json&titles=Albert%20Einstein&prop=categories"
(for the example of Albert Einstein)
但我发现很难从 MediaWiki API 文档页面了解我是否需要 token 和哈希,或者是否需要登录。我知道有时候不需要登录。
现在我的代码是:
JSONArray wikiResult=null;
String url1= "http://en.wikipedia.org/w/api.php?action=query&format=json&titles=Albert%20Einstein&prop=categories";
wikiResult=ApiCall(url1);
其中 ApiCall 是一个发送调用的函数,它工作正常,我已经检查过了。 返回的 JSONArray 为空。
有人可以告诉我我做错了什么吗?
最佳答案
prop=categories
您不需要登录或获取 token 。
响应中可能会解释实际错误。您得到的结果可能是空的,因为响应不是 JSON(出现某些错误时会发生这种情况)。
如果我猜的话,我认为你没有设置 the User-Agent
header在您的要求中,is required by Wikimedia wikis .
关于java - 使用 eclipse 使用 wikipedia api 所需的 token (或其他东西),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19567733/