Skip to content

Update README.md to include SerpApiSearch sample #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hilmanski
Copy link

Many customers are confused about how to use this library with other search engines outside Google Search. This PR includes the generic SerpApiSearch class instruction.

For example: #23

Include the generic `SerpApiSearch` class instruction
Copy link

@tanys123 tanys123 left a comment

Choose a reason for hiding this comment

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

Thanks @hilmanski 👍

Comment on lines +112 to +116
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
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

@hilmanski
Copy link
Author

Thank you @tanys123 for the feedback. I haven't been able to test it locally. Still struggling with installing this library.

@tanys123
Copy link

Thank you @tanys123 for the feedback. I haven't been able to test it locally. Still struggling with installing this library.

Yea, it is not a straightforward one, I guess we should take some time to clean up the repo. I was also banging here and there to get it to work.

I am able to get it to work this way:

  1. Following the Makefile in the /demo folder, you should first run init clean then build (yea, not dep).
  2. Even though you get error from build step, but the java library files should be downloaded in the ${root}/build folder, then this time run dep -- if it fails, just manually copy the libs folder into /demo
  3. Update the dependencies settings in build.gradle. The important part is to replace the remote repo with the local version (implementation fileTree(dir: "./libs", includes: ['*.jar']))
--- a/demo/build.gradle
+++ b/demo/build.gradle
 dependencies {
-    // implementation fileTree(dir: "./libs", includes: ['*.jar'])
+    // Use local JAR files from libs directory
+    implementation fileTree(dir: "./libs", includes: ['*.jar'])
     implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
-    implementation 'com.github.serpapi:google-search-results-java:2.0.3'
 }
  1. Now running make build should work, which mean running make run should work too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants