serpapi / serpapi-java

Official Java wrapper for SerpApi HTTP endpoints
MIT License
1 stars 1 forks source link

Errors When Running the Demo #1

Open schaferyan opened 9 months ago

schaferyan commented 9 months ago

Currently, the Demo can't be run by following the directions in the README. Hopefully we can either update the readme to reflect the necessary process, or make any fixes needed.

I ran into the following issues, some of which also occurred with the older google-search-results-java:

  1. When running the example via make, "API_KEY" needs to be capitalized or it will return an error
  2. After that, I receive this error:
/bin/sh: ./gradlew: No such file or directory
make: *** [run] Error 127

We need to run make all or make init to initialize the gradle wrapper in the demo folder.

  1. Some tests fail during make dep:
serpapi.BingTest > search FAILED
    java.lang.AssertionError at BingTest.java:34

serpapi.GooglePlayTest > search FAILED
    java.lang.AssertionError at GooglePlayTest.java:36

serpapi.GoogleProductTest > search FAILED
    java.lang.ClassCastException at GoogleProductTest.java:35

serpapi.YahooTest > search FAILED
    java.lang.AssertionError at YahooTest.java:34

This occurs regardless of whether the local .jar file or downloading from Jitpack is indicated in build.gradle. It seems to only occur in this library, not in the old google-search-results-java library.

  1. If I ignore this and continue to make build, I run into one of two issues depending on how the dependency is declared in build.gradle.

If implementation fileTree(dir: "./libs", includes: ['*.jar']) is uncommented, I run into a similar issue to the one reported here.

> Task :compileJava FAILED
/Users/schaf/repos/serpapi-java/demo/src/main/java/demo/App.java:14: error: package serpapi does not exist
import serpapi.SerpApi;
              ^
/Users/schaf/repos/serpapi-java/demo/src/main/java/demo/App.java:15: error: package serpapi does not exist
import serpapi.SerpApiException;
              ^
/Users/schaf/repos/serpapi-java/demo/src/main/java/demo/App.java:18: error: cannot find symbol
    public static void main(String[] args) throws SerpApiException {
                                                  ^
  symbol:   class SerpApiException
  location: class App
/Users/schaf/repos/serpapi-java/demo/src/main/java/demo/App.java:34: error: cannot find symbol
        SerpApi serpapi= new SerpApi(parameter);
        ^
  symbol:   class SerpApi
  location: class App
/Users/schaf/repos/serpapi-java/demo/src/main/java/demo/App.java:34: error: cannot find symbol
        SerpApi serpapi= new SerpApi(parameter);
                             ^
  symbol:   class SerpApi
  location: class App
/Users/schaf/repos/serpapi-java/demo/src/main/java/demo/App.java:44: error: cannot find symbol
        } catch (SerpApiException e) {
                 ^
  symbol:   class SerpApiException
  location: class App
6 errors

Also, there are some deprecation warnings from Gradle:

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

If implementation 'com.github.serpapi:serpapi:1.0.0' is uncommented I get the following error:

Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not resolve com.github.serpapi:serpapi:1.0.0.
     Required by:
         project :
      > Could not resolve com.github.serpapi:serpapi:1.0.0.
         > Could not get resource 'https://jitpack.io/com/github/serpapi/serpapi/1.0.0/serpapi-1.0.0.pom'.
            > Could not GET 'https://jitpack.io/com/github/serpapi/serpapi/1.0.0/serpapi-1.0.0.pom'. Received status code 401 from server: Unauthorized
jvmvik commented 9 months ago

thanks for the detailed report. 1- environment variable are always capitalized (common naming convention in *unix world). API_KEY. did you see a reference where it's not the case? 2- yeah, make all is always recommended at first. gradle has weird behavior. 3- make dep shouldn't have run the test. I modified the make file target to run skip running the tests. 4- I switched the demo to download the jar file from jitpack instead of local build, and fix the dependency. com.github.serpapi:serpapi:1.0.0 : incorrect 'com.github.serpapi:serpapi-java:1.0.0' : correct

Good news. no new release required. only documentation fixes those issues. I have already pushed a change. can you double check if it resolved your concerns ?

jvmvik commented 9 months ago

tests are now all passing. https://github.com/serpapi/serpapi-java/actions/runs/7372604777

The documentation was updated to reflect best pratice. Let's me know if I can close this ?

schaferyan commented 9 months ago

Excellent, thank you @jvmvik! It works now!

My only further recommendation is to revise the Usage section of the Readme to reflect a few of the points addressed above.

1- environment variable are always capitalized (common naming convention in *unix world). API_KEY. did you see a reference where it's not the case? 2- yeah, make all is always recommended at first. gradle has weird behavior.

The current documentation reads:

To get started with this project in Java. We provided a fully working example.

git clone https://github.com/serpapi/serpapi-java.git
cd serpapi-java/demo
make run api_key=<your private key>

My suggestion is just to capitalize API_KEY and use make all:

To get started with this project in Java. We provided a fully working example.

git clone https://github.com/serpapi/serpapi-java.git
cd serpapi-java/demo
make all API_KEY=<your private key>