Open Nikhiladiga opened 8 months ago
@Nikhiladiga Apologies for the dreadfully slow response. This is indeed our issue where the GoogleSearch
class is forcing engine=google
and ignoring whatever engine
you set instead. Although I think the main issue is our API documentation suggests using GoogleSearch
when perhaps it shouldn't considering how the class is implemented.
I recommend using the generic SerpApiSearch
class to set other engines such as Google Lens. Below is your code updated with the SerpApiSearch
class. It should work as you expect.
public void requestSerpApiServer() {
Map<String, String> parameter = new HashMap<>();
parameter.put("engine", "google_lens");
parameter.put("url", "https://i.imgur.com/HBrB8p0.png");
parameter.put("api_key", serpApiKey);
SerpApiSearch search = new SerpApiSearch(parameter);
try {
JsonObject results = search.getJson();
JsonElement searchResults = results.get("knowledge_graph");
System.out.println(searchResults);
} catch (SerpApiSearchException e) {
e.printStackTrace();
}
}
I have the following piece of code written for a Spring Boot server
This was copied from the example in the serp API playground. I'm facing this issue when I try to run this code
Am I missing something or is this is a bug?