|
| 1 | +# Google Maps Reviews Scraper With Java |
| 2 | + |
| 3 | +The library provides real-time access to the reviews from Google Maps via [Outscraper API](https://app.outscraper.com/api-docs#tag/Google-Reviews). |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +Java 11 or later |
| 8 | + |
| 9 | +### Gradle |
| 10 | + |
| 11 | +Edit your build.gradle file |
| 12 | +``` sh |
| 13 | +repositories { |
| 14 | + maven { url "https://jitpack.io" } |
| 15 | +} |
| 16 | + |
| 17 | +dependencies { |
| 18 | + implementation 'com.github.outscraper:outscraper-java:v1.0.4' |
| 19 | +} |
| 20 | +``` |
| 21 | +
|
| 22 | +### Maven |
| 23 | +
|
| 24 | +Add the JitPack repository to your build file |
| 25 | +``` sh |
| 26 | + <repositories> |
| 27 | + <repository> |
| 28 | + <id>jitpack.io</id> |
| 29 | + <url>https://jitpack.io</url> |
| 30 | + </repository> |
| 31 | + </repositories> |
| 32 | +``` |
| 33 | +
|
| 34 | +Add the dependency |
| 35 | +``` sh |
| 36 | + <dependency> |
| 37 | + <groupId>com.github.outscraper</groupId> |
| 38 | + <artifactId>outscraper-java</artifactId> |
| 39 | + <version>v1.0.4</version> |
| 40 | + </dependency> |
| 41 | +``` |
| 42 | +
|
| 43 | +### Others |
| 44 | +
|
| 45 | +You'll need to manually install the following JARs: |
| 46 | +- [The Outscraper JAR](https://jitpack.io/com/github/outscraper/outscraper-java/v1.0.4/outscraper-java-v1.0.4.jar) |
| 47 | +- [Json](https://repo1.maven.org/maven2/org/json/json/20090211/json-20090211.jar) |
| 48 | +- [Httpcomponents](https://repo1.maven.org/maven2/org/apache/httpcomponents/httpclient/4.5.13/httpclient-4.5.13.jar) |
| 49 | +- [Guava](https://repo1.maven.org/maven2/com/google/guava/guava/30.1.1-jre/guava-30.1.1-jre.jar) |
| 50 | +
|
| 51 | +## Initialization |
| 52 | +```java |
| 53 | +OutscraperClient client = new OutscraperClient("SECRET_API_KEY"); |
| 54 | +``` |
| 55 | +[Link to the profile page to create the API key](https://app.outscraper.com/profile) |
| 56 | +
|
| 57 | +## Usage |
| 58 | +
|
| 59 | +```java |
| 60 | +// Get reviews of the specific place by id |
| 61 | +JSONArray results = client.googleMapsReviewsV3(new HashMap<String, Object>() {{ |
| 62 | + put("query", "ChIJrc9T9fpYwokRdvjYRHT8nI4"); |
| 63 | + put("reviewsLimit", 20); |
| 64 | + put("language", "en"); |
| 65 | +}}); |
| 66 | +System.out.println(results); |
| 67 | +
|
| 68 | +// Get reviews for places found by search query |
| 69 | +JSONArray results = client.googleMapsReviewsV3(new HashMap<String, Object>() {{ |
| 70 | + put("query", "Memphis Seoul brooklyn usa"); |
| 71 | + put("reviewsLimit", 20); |
| 72 | + put("limit", 20); |
| 73 | + put("language", "en"); |
| 74 | +}}); |
| 75 | +System.out.println(results); |
| 76 | +
|
| 77 | +// Get only new reviews during last 24 hours |
| 78 | +Integer yesterdayTimestamp = 1657980986; |
| 79 | +JSONArray results = client.googleMapsReviewsV3(new HashMap<String, Object>() {{ |
| 80 | + put("query", "ChIJrc9T9fpYwokRdvjYRHT8nI4"); |
| 81 | + put("sort", "newest"); |
| 82 | + put("cutoff", yesterdayTimestamp); |
| 83 | + put("reviewsLimit", 100); |
| 84 | + put("language", "en"); |
| 85 | +}}); |
| 86 | +System.out.println(results); |
| 87 | +``` |
0 commit comments