Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ https://jitpack.io/api/builds/com.github.serpapi/google-search-results-java

Note: jitpack.io enables to download maven package directly from github release.

## Quick start
## Quick start for Google Search

To get started with this project in Java.
We provided a fully working example.
Expand Down Expand Up @@ -101,6 +101,30 @@ The class GoogleSearch
- Parse JSON into Ruby Hash using JSON standard library provided by Ruby
Et voila..

## Usage for other search engines
For other search engines, you can use the `SerpApiSearch` class and adjust the `engine`.
Example for our Google Lens API:

```
public void runSearch() {
Map<String, String> parameter = new HashMap<>();

parameter.put("engine", "google_lens"); // You can adjust the engine here
parameter.put("url", "https://i.imgur.com/HBrB8p0.png");
parameter.put("api_key", serpApiKey);

SerpApiSearch search = new SerpApiSearch(parameter); // Use SerpApiSearch class
Comment on lines +112 to +116
Copy link

@tanys123 tanys123 Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Base on the implementation, api_key and engine should pass as method parameter else exception is raised:

public SerpApiSearch(Map<String, String> parameter, String api_key, String engine) {
this.parameter = parameter;
this.api_key = api_key;
this.engine = engine;

Suggested change
parameter.put("engine", "google_lens"); // You can adjust the engine here
parameter.put("url", "https://i.imgur.com/HBrB8p0.png");
parameter.put("api_key", serpApiKey);
SerpApiSearch search = new SerpApiSearch(parameter); // Use SerpApiSearch class
parameter.put("url", "https://i.imgur.com/HBrB8p0.png");
SerpApiSearch search = new SerpApiSearch(parameter, serpApiKey, "google_lens"); // Use SerpApiSearch class


try {
JsonObject results = search.getJson();
JsonElement searchResults = results.get("visual_matches");
System.out.println(searchResults);
} catch (SerpApiSearchException e) {
e.printStackTrace();
}
}
```

Alternatively, you can search:
- Bing using BingSearch class
- Baidu using BaiduSearch class
Expand Down
Loading