mediawikimediawiki-apiwikimedia-commonswikimedia-android-data-clientwikibase

Get depictions from Wikimedia Commons


Wikimedia Commons has a new feature to describe what a picture depicts. Example:

enter image description here

Question

How to get the "depicts" of a given image, as JSON, using either a wikimedia-android-data-client library call or a REST HTTP request?


Solution

  • You can use some of the Wikibase APIs (exactly which or how is not well-documented at the moment, I think). E.g.

    https://commons.wikimedia.org/w/api.php?action=wbgetclaims&format=jsonfm&entity=M78893847

    {
        "claims": {
            "P180": [
                {
                    "mainsnak": {
                        "snaktype": "value",
                        "property": "P180",
                        "hash": "7754bb4b4dcf94dd0a6b8524351b22df21328a88",
                        "datavalue": {
                            "value": {
                                "entity-type": "item",
                                "numeric-id": 12280,
                                "id": "Q12280"
                            },
                            "type": "wikibase-entityid"
                        },
                        "datatype": "wikibase-item"
                    },
                    "type": "statement",
                    "id": "M78893847$bf7f116a-4d08-0426-0e81-c9552a89fa63",
                    "rank": "preferred"
                },
                {
                    "mainsnak": {
                        "snaktype": "value",
                        "property": "P180",
                        "hash": "8ed7e126588c21d3cf88387d5ee875d528c00a74",
                        "datavalue": {
                            "value": {
                                "entity-type": "item",
                                "numeric-id": 1021645,
                                "id": "Q1021645"
                            },
                            "type": "wikibase-entityid"
                        },
                        "datatype": "wikibase-item"
                    },
                    "type": "statement",
                    "id": "M78893847$7830fc04-4a1e-f289-93bc-69d6bbf3b7fd",
                    "rank": "normal"
                }
            ]
        }
    }
    

    78893847 being the page ID which you can get via the query API: https://commons.wikimedia.org/w/api.php?action=query&format=jsonfm&formatversion=2&titles=File%3AMomoyo-brug%20in%20Shibaura%2C%20gezien%20richting%20het%20zuidoosten%2C%20-15%20maart%202019.jpg

    {
        "batchcomplete": true,
        "query": {
            "pages": [
                {
                    "pageid": 78893847,
                    "ns": 6,
                    "title": "File:Momoyo-brug in Shibaura, gezien richting het zuidoosten, -15 maart 2019.jpg"
                }
            ]
        }
    }