har*_*son 1 mediawiki wikipedia wikipedia-api mediawiki-api
我正在调用维基百科API,它返回该位置的标题,镜头文本,图像和地理坐标.我的维基百科API是:
https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts|pageimages|coordinates&titles=Berlin&redirects=1&formatversion=2&exintro=1&explaintext=1&piprop=thumbnail&pithumbsize=400
Run Code Online (Sandbox Code Playgroud)
此外,我正在使用另一个Wikipedia API,它根据地理坐标返回地名列表:
https://en.wikipedia.org/w/api.php?format=json&action=query&list=geosearch&gsradius=1000&gscoord=52.5243700|13.4105300&gslimit=50&gsprop=type|dim|globe
Run Code Online (Sandbox Code Playgroud)
对于第二个API,我得到这样的响应:
"query": {
"geosearch": [
{
"pageid": 28782169,
"ns": 0,
"title": "1757 Berlin raid",
"lat": 52.523405,
"lon": 13.4114,
"dist": 122.4,
"primary": "",
"type": null,
"dim": 1000
},
{
"pageid": 526195,
"ns": 0,
"title": "Scheunenviertel",
"lat": 52.526111111111,
"lon": 13.41,
"dist": 196.9,
"primary": "",
"type": "landmark",
"dim": 1000
},
...
]
}
Run Code Online (Sandbox Code Playgroud)
现在我想在一个API中组合这两个搜索.我想在第二个API中添加第一个API的信息,如下所示:
"query": {
"geosearch": [
{
"pageid": 28782169,
"ns": 0,
"title": "1757 Berlin raid",
"lat": 52.523405,
"lon": 13.4114,
"dist": 122.4,
"primary": "",
"type": null,
"dim": 1000
"pages": [
{
"pageid": 28782169,
"ns": 0,
"title": "1757 Berlin raid",
"extract": "Berlin is the capital of Germany and one of the 16 states of Germany. With a population of 3.5 million people, it is the second most populous city proper and the seventh.........",
"thumbnail": {
"source": "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Siegessaeule_Aussicht_10-13_img4_Tiergarten.jpg/400px-Siegessaeule_Aussicht_10-13_img4_Tiergarten.jpg",
"width": 400,
"height": 267
}
}
]
},
...
]
}
Run Code Online (Sandbox Code Playgroud)
我想知道这有可能吗?
所以,如果我理解正确的,你想用一个维基百科的API请求获得冠军,射击,文字,图像和地理cordinates(你的第一个API)为位于在一定区域内的所有地方(维基百科文章)由下式给出坐标和半径(您的第二个API).如果这是正确的,您可以这样做:
主要参数:format=json&action=query
查询参数:
redirects=1generator=geosearch (您的第二个API:见第3点)prop=extracts|coordinates|pageimages (您的第一个API:请参阅第4,5和6点)geosearch参数(所有生成器参数都以"g"为前缀):
ggslimit=20- 您查询的总结果(因为exlimit=20)ggsradius=1000&ggscoord=52.5243700|13.4105300 - 这是你的切入点提取参数 :( exintro=1&explaintext=1&exlimit=20最大exlimit为20)
坐标参数 :( coprop=type|dim|globe&colimit=20最大值colimit为500)
为pageimages参数:piprop=thumbnail&pithumbsize=400&pilimit=20(最大为50)
你怎么看,最大值colimit是500,最大值pilimit是50,但我们不能使用超过20,因为exlimit.
或者最后,您的请求将是以上所有参数的加入:
https://en.wikipedia.org/w/api.php?format=json&action=query&redirects=1&generator=geosearch&prop=extracts|coordinates|pageimages&ggslimit=20&ggsradius=1000&ggscoord=52.5243700|13.4105300&exintro=1&explaintext=1&exlimit=20&coprop=type|dim|globe&colimit=20&piprop=thumbnail&pithumbsize=400&pilimit=20
Run Code Online (Sandbox Code Playgroud)
以下是回复:
"query":{
"pages":{
"2511":{
"pageid":2511,
"ns":0,
"title":"Alexanderplatz",
"extract":"Alexanderplatz (pronounced [\u0294al\u025bk\u02c8sand\u0250\u02ccplats]) is a large public square and transport hub in the central Mitte district of Berlin, near the Fernsehturm. Berliners often call it simply Alex, referring to a larger neighbourhood stretching from Mollstra\u00dfe in the northeast to Spandauer Stra\u00dfe and the Rotes Rathaus in the southwest.",
"coordinates":[
{
"lat":52.52166748,
"lon":13.41333294,
"primary":"",
"type":"landmark",
"dim":"1000",
"globe":"earth"
}
],
"thumbnail":{
"source":"https://upload.wikimedia.org/wikipedia/commons/thumb/d/da/Alexanderplatz_by_the_night_-_ProtoplasmaKid.webm/400px--Alexanderplatz_by_the_night_-_ProtoplasmaKid.webm.jpg",
"width":400,
"height":225
}
},
...
},
}
Run Code Online (Sandbox Code Playgroud)