google-apigoogle-knowledge-graph

INVALID_ARGUMENT exception when requesting Google's knowledge graph API


I've read the documentation on Google's knowledge graph and from what I understand we can search for results both based on a query and based on IDs. For getting results by a query, no problem whatsoever, but when I try to retrieve them by IDs, it fails. Setting aside what query I used myself, this is the request URL I got from Google's API Explorer:

https://kgsearch.googleapis.com/v1/entities:search?ids=kg%3A%2Fm%2F01nrz4&key={YOUR_API_KEY}

and the result is:

{
 "error": {
  "code": 400,
  "message": "Request contains an invalid argument.",
  "status": "INVALID_ARGUMENT"
 }
}

And I'm pretty sure that the problem is with the ids parameter. Am I missing something?

Thanks


Solution

  • OK, so here's the thing. Each found instance has an attribute like this: "@id": "kg:/m/0gkg6" . So in this instance the id is kg:/m/0gkg6, but when we want to run a query based on ID, we should omit the kg: part.