0

I have stored some search results of the the google knowledge Graph API (GKGA) in the form of ids, that the GKGA returns.

Now I want to get the whole Result again using the id, but that doesnt seem to work. After some research I found a query that works from here: How to use Google Knowledge Graph API

My requests are a bit different mainly the id:

https://kgsearch.googleapis.com/v1/entities:search?callback=jQuery321016748583817510942_1521200076900&indent=true&key={MY_API_KEY}&ids=kg:/m/031sc&_=1521200076901

The refereced working request is:

https://kgsearch.googleapis.com/v1/entities:search?ids=%2Fm%2F014nm_&key={API-KEY}

The main difference I could see was that the ids are different:

mine was:

  • mine was: kg:/m/031sc
  • his was: kg:/m/014nm_ but is %2Fm%2F014nm_ in the url

So I tried to use encodeURI on the id and whole url but made no difference.

So here is the question: What do I need to do with my id(s) so that I get the results of the GKGA?

Currently Im implementing my request like this: (if you were wondering about the JQuery part in my request-url)

let service_url = 'https://kgsearch.googleapis.com/v1/entities:search';
let requestParams = {
                'indent': true,
                'key': '{API-KEY}',
                "ids":"kg:/m/031sc"
            };
$.getJSON(service_url + '?callback=?', requestParams, (response) => {
}).done((response) => {
      console.log('Response is: ' + JSON.stringify(response));
});
telion
  • 834
  • 1
  • 9
  • 34

1 Answers1

2

The solution that worked for me was using the part after the ':' as the actual id. That let to the following solution that supports more than on id:

    let service_url = 'https://kgsearch.googleapis.com/v1/entities:search';
    let dataurl = 'key={API-KEY}'; //just the key, not the moustaches '{','}'
    for (let i = 0; i < allIds.length; i++) {
        dataurl += '&ids='+ allIds[i].split(':')[1];
    }
    $.getJSON(service_url + '?callback=?', dataurl, (response) => {
    }).done((response) => {});
telion
  • 834
  • 1
  • 9
  • 34
  • 1
    If a developer of the google-knowledge Graph sees this, mind mentioning the correct way of request with id in the documentation of GKGA? – telion Mar 16 '18 at 15:24