如何将两个维基百科 API 调用合并为一个?
How to combine two Wikipedia API calls into one?
我正在调用维基百科 API,其中 returns 标题、Shot-Text、图像和该位置的 geo-cordinates。我的维基百科 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
我还在使用另一个维基百科 API,其中 returns 根据 geo-coordinates:
的地名列表
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
第二次 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
},
...
]
}
现在我想将这两个搜索合并为一个 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
}
}
]
},
...
]
}
我想知道这样可以吗?
所以,如果我没理解错的话,你想要一个维基百科 API 请求来获得 title, shot-text、image 和 geo-cordinates(您的第一个 API)用于位于特定位置的所有地点(维基百科文章)给定坐标和半径的区域(你的第二个 API)。如果正确的话,你可以这样做:
main parameters: format=json&action=query
-
redirects=1
generator=geosearch
(你的第二个API:见第3点)
prop=extracts|coordinates|pageimages
(您的第一个 API:参见第 4、5 和 6 点)
geosearch parameters(所有生成器参数都以"g"为前缀):
ggslimit=20
- 您的查询总结果(因为 exlimit=20
)
ggsradius=1000&ggscoord=52.5243700|13.4105300
- 这是您的入口点
parameters for extracts: exintro=1&explaintext=1&exlimit=20
(最大值 exlimit
为 20)
parameters for coordinates: coprop=type|dim|globe&colimit=20
(最大值 colimit
为 500)
parameters for 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
这是回复:
"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
}
},
...
},
}
我正在调用维基百科 API,其中 returns 标题、Shot-Text、图像和该位置的 geo-cordinates。我的维基百科 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
我还在使用另一个维基百科 API,其中 returns 根据 geo-coordinates:
的地名列表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
第二次 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
},
...
]
}
现在我想将这两个搜索合并为一个 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
}
}
]
},
...
]
}
我想知道这样可以吗?
所以,如果我没理解错的话,你想要一个维基百科 API 请求来获得 title, shot-text、image 和 geo-cordinates(您的第一个 API)用于位于特定位置的所有地点(维基百科文章)给定坐标和半径的区域(你的第二个 API)。如果正确的话,你可以这样做:
main parameters:
format=json&action=query
-
redirects=1
generator=geosearch
(你的第二个API:见第3点)prop=extracts|coordinates|pageimages
(您的第一个 API:参见第 4、5 和 6 点)
geosearch parameters(所有生成器参数都以"g"为前缀):
ggslimit=20
- 您的查询总结果(因为exlimit=20
)ggsradius=1000&ggscoord=52.5243700|13.4105300
- 这是您的入口点
parameters for extracts:
exintro=1&explaintext=1&exlimit=20
(最大值exlimit
为 20)parameters for coordinates:
coprop=type|dim|globe&colimit=20
(最大值colimit
为 500)parameters for 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
这是回复:
"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
}
},
...
},
}