How to obtain Wikidata ID from English Wikipedia article name, also for redirects? Is there API call?
Example:
Karachi >> Q8660
Karaachi >> Q8660
How to approach changes in assignment? Now Media in Karachi is redirect to Media of Pakistan (Wikidata item Q6805922), but can be own article later.
Display multilingual information from Wikidata in your application. This page shows how to retrieve and present relevant information from Wikidata by associating it with entities in your application.
Access from Wikipedia From a Wikipedia page, you can go to the link "Wikidata item", using "Tools" in the side panel (in the left), to see and edit it. Also in Tools, there is another link to "page information", where is "Wikidata item ID", that contains the QID (for example: Q171 or "None").
As of November 2018, Wikidata information was used in 58.4% of all English Wikipedia articles, mostly for external identifiers or coordinate locations.
You can query the data in Wikidata through our SPARQL endpoint, the Wikidata Query Service. The service can be used both as an interactive web interface, or programmatically by submitting GET or POST requests to https://query.wikidata.org/sparql .
Use Wikipedia API to create a query with property pageprops and resolving redirects:
https://en.wikipedia.org/w/api.php?action=query&prop=pageprops&ppprop=wikibase_item&redirects=1&titles=ARTICLE_NAME
In your case, for Wikipedia articles "Media in Karachi" and "Media of Pakistan" you will get the same Wikidata item ID: Q6805922. Same thing for "Karaachi" and "Karachi" → Q8660.
As well as the accepted answer you can also use the Wikidata API directly passing in a site and a title.
The docs are at https://www.wikidata.org/w/api.php?action=help&modules=wbgetentities
Get the entity for http://en.wikipedia.org/wiki/Karachi:
I needed to do it in Google Sheets, and was able to do it with a formula like this. It assumes the Wikipedia title is in column B. Copy down to the rows you need
=IMPORTXML(concat("https://en.wikipedia.org/w/api.php?action=query&prop=pageprops&ppprop=wikibase_item&redirects=1&format=xml&titles=",B1),"//@wikibase_item")
Another suggestion is to use the dump https://dumps.wikimedia.org/enwiki/latest/enwiki-latest-page_props.sql.gz, 230Mb zipped
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With