I am making a web application and I want the born date of the personalities on my pages. I want to use the Wikipedia API to get the born data but I can't find the correct URL to get the born date. Can anyone help?
Asked
Active
Viewed 323 times
1
-
Does this answer your question? [get birthdate, birthplace from mediawiki xml format api](https://stackoverflow.com/questions/17854633/get-birthdate-birthplace-from-mediawiki-xml-format-api) – Pat Myron Jun 02 '23 at 17:08
1 Answers
0
You need to use the Wikidata API for this. wikidata api retrieve properties from entity (wikidata entry) has an example and expanding upon that, use e.g. https://en.wikipedia.org/w/api.php?action=query&prop=pageprops&ppprop=wikibase_item&titles=Donald%20Trump&formatversion=2 to get the Wikidata ID, then use https://www.wikidata.org/w/api.php?action=wbgetentities&props=claims&ids=Q22686&format=json and the date of birth exists at e.g.
json['entities']['Q22686']['claims']['P569'][0]['mainsnak']['datavalue']['value']['time']
There's probably a more elegant way to do it using SPARQL too https://wdqs-tutorial.toolforge.org/

smartse
- 1,026
- 7
- 12