I have been struggling with Google Knowledge Graph Search API
for Android for 2 days now, according to Google here all I have to do is download the Google Knowledge Graph Search API
zip here and import it into my project but for Android I am advised to use the Google Play Services API
as explained here developers.google.com/api-client-library/java/google-api-java-client/setup#android
(sorry about this link, because of low stats I was not allowed to post more than 2 links so I improvised) , then there is a piece of java code supplied which can be used to query the API
below is the code
private void doSearch() {
System.out.println("search started");
Properties properties = new Properties();
try
{
properties.load(new FileInputStream("kgsearch.properties"));
HttpTransport httpTransport = new NetHttpTransport();
HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
JSONParser parser = new JSONParser();
GenericUrl url = new GenericUrl("https://kgsearch.googleapis.com/v1/entities:search");
url.put("query", "Taylor Swift");
url.put("limit", "10");
url.put("indent", "true");
url.put("key", properties.get(ConstantsUtil.GOOGLE_API_KEY));
HttpRequest request = requestFactory.buildGetRequest(url);
HttpResponse httpResponse = request.execute();
JSONObject response = (JSONObject) parser.parse(httpResponse.parseAsString());
JSONArray elements = (JSONArray) response.get("itemListElement");
for(int i = 0; i < elements.length(); i++)
{
System.out.println(JsonPath.read(elements.getJSONObject(i), "$.result.name").toString());
}
}catch(Exception e)
{
e.printStackTrace();
}
System.out.println("search ended");
}
but this code is not complete, when I run it, it complains about a missing file kgsearch
java.io.FileNotFoundException: /kgsearch.properties: open failed: ENOENT (No such file or directory)
but my questions is how do I fix it? is there anybody who has ever used the Google Knowledge Graph API
with a more working sample code I could use? if there is any please help.