Search code examples
javascriptgoogle-apigoogle-knowledge-graph

Google Knowledge Graph API does not return results


I want to display results pulled using Google Knowledge Graph API by using the javascript code provided by the official documentation on my HTML file. Refer here:

  var service_url = 'https://kgsearch.googleapis.com/v1/entities:search';
 var params = {
    'query': 'united_kingdom',
    'limit': 10,
    'indent': true,
    'key': '(myapikey)',
  };
  $.getJSON(service_url + '?callback=?', params, function(response) {
    $.each(response.itemListElement, function(i, element) {
      $('<div>', {text:element['result']['name']}).appendTo(document.body);
 
    });
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Why isn't it returning any result? I inspected it and saw that there is a javascript error (undefined).


Solution

  • I think that your script is correct. In my environment, your script worked. So can you confirm the following points?

    1. Confirm whether Knowledge Graph Search API is enabled at the project that you have the API key?
      • You can see it at here.
    2. Confirm whether the API is correct.

    If this was not useful for you, I'm sorry.