youtubeyoutube-apifreebasewikidatawikidata-api

How can I query wikidata with a freebase id from a youtube video?


I am using the youtube API to retrieve the freebase topic details of particular videos. Since freebase is closing down how do I use wikidata to query for a specific topic id?

For example the following topic id /m/0181lj should give the following information

/m/0181lj

I have tried playing with the wikidata REST API but I haven't found a request which matches what I need.

Update

Freebase have released the Knowledge graph which allows you to query via topicId as so

https://kgsearch.googleapis.com/v1/entities:search?ids=/m/0181lj&key=API_KEY&limit=5&indent=True

However, some ids don't seem to be returning data e.g. the following music genres /m/05fqyx, /m/02w1p3

As an alternative freebase can be downloaded, but I haven't tried that just yet!


Solution

  • There isn't a Wikidata equivalent to the Freebase Suggest, Search, or Topic APIs.

    They've got a beta SPARQL endpoint that you could use to (painfully) roll your own replacement for Freebase Topic (details below), but if you don't have an immediate need to migrate, you might consider waiting until the new, promised, Knowledge Graph equivalents are available. Google has promised a 3 month transition period after the availability of the new APIs before they shut down Freebase. (But you need to decide how willing you are to trust them.)

    The other advantage to delaying the transition is that it gives the Wikidata folks more time to get their act together and build some usable APIs. Of course, you need to be able to live with the fact that Freebase is read-only.

    If you want to roll your own Wikidata query for Freebase IDs, you can use the following query as a starting point:

    PREFIX wd: <http://www.wikidata.org/entity/>
    PREFIX wdt: <http://www.wikidata.org/prop/direct/>
    PREFIX wikibase: <http://wikiba.se/ontology#>
    
    SELECT  ?s ?sLabel ?p ?o ?oLabel WHERE {
     ?s ?p ?o .
     ?s wdt:P646 "/m/0181lj" .
    
       SERVICE wikibase:label {
        bd:serviceParam wikibase:language "en" .
       }
     }
    

    TinyURL to query editor http://tinyurl.com/otdc78s

    You can get back JSON results by sending the query to the API endpoint with this base URL https://query.wikidata.org/bigdata/namespace/wdq/sparql?format=json&query= followed by your URL encoded query

    TinyURL to API call http://tinyurl.com/nfcp2rh