问题
I want to get the first and the last revision timestamp of a wikidata Item (for example Kevin Kratz), I tried with the wikidata api:
-first timestamp: https://www.wikidata.org/w/api.php?action=query&titles=Kevin+Kratz&prop=revisions&rvdir=newer&rvlimit=1&format=json
-last timestamp: https://www.wikidata.org/w/api.php?action=query&prop=revisions&rvlimit=1&rvprop=timestamp&titles=Kevin+Kratz&format=json
but it didn't return the timestamps:
{"batchcomplete":"","query":{"pages":{"-1":{"ns":0,"title":"Kevin Kratz","missing":""}}}}
回答1:
Use there Api Sandbox to create the query.
Set list=allrevisions to get all the revisions.
Use arvlimit
to 1
to limit the response to 1 revision.
Sort the list to newer
or older
to get the first/last;
arvdir=newer
arvdir=older
Final url;
https://www.wikidata.org/w/api.php?action=query&format=json&list=allrevisions&titles=Kevin%20Kratz&arvprop=ids|timestamp|flags|comment|user&arvlimit=1&arvdir=older
Result (Just the timestamps..)
-> newer
"timestamp": "2004-07-16T02:43:38Z",
-> Older
"timestamp": "2020-03-06T16:33:59Z",
Link to Api sandbox with filled data
Full response (arvdir=older
)
{
"batchcomplete": "",
"continue": {
"arvcontinue": "20200306164040|1130467581",
"continue": "-||"
},
"query": {
"pages": {
"-1": {
"ns": 0,
"title": "Kevin Kratz",
"missing": ""
}
},
"allrevisions": [
{
"pageid": 86050197,
"revisions": [
{
"revid": 1130467582,
"parentid": 1130467581,
"user": "KrBot",
"timestamp": "2020-03-06T16:40:41Z",
"comment": "/* wbsetdescription-add:1|es */ categoría de Wikimedia"
}
],
"ns": 0,
"title": "Q86805230"
}
]
}
}
来源:https://stackoverflow.com/questions/60567772/get-wikidata-first-and-last-revision-timestamp