serpapi / google-search-results-java

Google Search Results JAVA API via SerpApi
https://serpapi.com
MIT License
33 stars 24 forks source link

Cant get this artifact from jitpack #22

Open ai-for-java opened 1 year ago

ai-for-java commented 1 year ago

Hello,

How do I get this library in maven? Could you please help?

This is what I have in my pom.xml: `

com.github.serpapi
        <artifactId>google-search-results-java</artifactId>
        <version>2.0.3</version>
    </dependency>`

and: `

jitpack.io https://www.jitpack.io
</repositories>`

But I am always getting this error: [ERROR] Failed to execute goal on project xxx: Could not resolve dependencies for project xxx: The following artifacts could not be resolved: com.github.serpapi:google-search-results-java:jar:2.0.3 (absent): Could not find artifact com.github.serpapi:google-search-results-java:jar:2.0.3 in jitpack.io (https://www.jitpack.io)

Thank you!

HamaWhiteGG commented 1 year ago

I have encountered the same issue and hope it can be resolved. Thank you.

steelcityamir commented 1 year ago

Any update on this? I am also experiencing this issue.

HamaWhiteGG commented 1 year ago

@codebyamir Temporary Solution, I copied this code into my project langchain-java and pushed it to the Maven repository. https://github.com/HamaWhiteGG/langchain-java

You can use the following Maven dependency:

<!-- https://mvnrepository.com/artifact/io.github.hamawhitegg/serpapi-client -->
<dependency>
    <groupId>io.github.hamawhitegg</groupId>
    <artifactId>serpapi-client</artifactId>
    <version>0.1.7</version>
</dependency>

Note that it requires Java 17 or later(Because my entire project is using Java 17.).

Here is an example code:

SerpApiSearch search = new GoogleSearch();

Map<String, String> parameter = new HashMap<>();
parameter.put("engine", "google");
parameter.put("google_domain", "google.com");
parameter.put("gl", "us");
parameter.put("hl", "en");
parameter.put("q", "High temperature in SF yesterday");

search.setParameter(parameter);

JsonObject result = search.getJson();
String searchResult = result.getAsJsonArray("organic_results")
  .get(0)
  .getAsJsonObject()
  .get("snippet")
  .getAsString();

System.out.println(searchResult);

The output is like:

See weather overview. San Francisco Temperature Yesterday. Maximum temperature yesterday: 69 °F (at 2:56 pm) Minimum temperature yesterday: 54 °F (at 4:56 am)
ilyazub commented 7 months ago

@jvmvik, may https://github.com/serpapi/google-search-results-java/pull/3 fix the artifacts downloading?

Edit:

@ai-for-java @codebyamir @HamaWhiteGG Follow the next steps to get artifacts from the jitpack:

  1. Add repository

    <repositories>
    <repository>
      <id>jitpack.io</id>
      <url>https://jitpack.io</url>
    </repository>
    </repositories>
  2. Add classifier to the dependency. (The package name contains the suffix: google-search-results-java-2.0.3-sources.jar.)

    <dependency>
      <groupId>com.github.serpapi</groupId>
      <artifactId>google-search-results-java</artifactId>
      <version>2.0.3</version>
      <classifier>sources</classifier>
    </dependency>
  3. Compile the project following the Maven's magic

    mvn clean install dependency:copy-dependencies package && javac -classpath .:target/dependency/* -d . $(find . -type f -name '*.java')`
  4. Run the code

    java -cp .:target/dependency/* Main

Full example: