Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Places API, how do I fetch the reviews?

A few people have asked this before but with no joy. But, it seems as though recently, google have offered the availability to fetch reviews from your google places via their api. https://developers.google.com/maps/documentation/javascript/places

I have the url that shows the json of the exact google place I want, however, I cannot see an example on how to fetch the reviews only from this and am completely stuck. Their example shows how to show the map, but not how to fetch the reviews only. Has anyone done this? If so, is there an example of how to do it? Thanks.

like image 910
Daniel Broughan Avatar asked Dec 31 '14 18:12

Daniel Broughan


People also ask

How do I get more than 5 reviews on Google Places API?

In order to have access to more than 5 reviews with the Google API you have to purchase Premium data Access from Google. That premium plan will grant you access to all sorts of additional data points you have to shell out a pretty penny.

How do I get data from Google Maps places API?

Go to APIs & Services → Dashboard → Enable APIs & Services at the top and Choose Maps Javascript API from the API Library. This will open up the Map JavaScript API page, and Enable it.

How to get places’ reviews on Google?

In the last blog, I talked about how to get places’ reviews on Google by Place API, but we can get only 5 reviews at most by “Place Details”. If you want to extract all reviews of each location, you can use “Google My Business API”.

What is Google Places API?

Tutorials on Natural Language Processing, Machine Learning, Data Extraction, and more Google places API allows developers to access a wealth of information from Google’s database for over 100 million places including location data, contact information, user ratings and reviews and more.

How to get more than 5 reviews with the Google API?

In order to have access to more than 5 reviews with the Google API you have to purchase Premium data Access from Google. That premium plan will grant you access to all sorts of additional data points you have to shell out a pretty penny. As a Business owner we can get all reviews through the MyBusiness API developers.google.com/my-business.

What can I do with the Google my Business API?

The Google My Business API provides you with the ability to work with review data to perform the following operations: List all reviews. Get a specific review. Get reviews from multiple locations. Reply to a review. Delete a review reply.


2 Answers

Once you have the id of a place you can do

  var request = {
    placeId: 'place-ID-here' // example: ChIJN1t_tDeuEmsRUsoyG83frY4
  };

  var service = new google.maps.places.PlacesService(map); // map is your map object

  service.getDetails(request, function(place, status) {
    if (status == google.maps.places.PlacesServiceStatus.OK) {
      console.log(place.reviews);
    }
  });

Update with full working example (https://codepen.io/gpetrioli/pen/OmQyEE)

var map, service;

function initMap() {
  var central_park = new google.maps.LatLng(40.764243, -73.973049);

  map = new google.maps.Map(document.getElementById("map"), {
    center: central_park,
    zoom: 14
  });

  var request = {
    location: central_park,
    radius: "500",
    types: ["food"]
  };

  service = new google.maps.places.PlacesService(map);
  service.nearbySearch(request, searchResult);
}

function searchResult(results, status) {
  if (status == google.maps.places.PlacesServiceStatus.OK) {
    // show first result on map and request for details
    var place = results[0];
    var marker = new google.maps.Marker({
      position: place.geometry.location,
      map: map,
      title: place.name
    });
    var infowindow = new google.maps.InfoWindow({
      content: place.name
    });
    infowindow.open(map, marker);

    service.getDetails({placeId: place.place_id}, function(place, status) {
      if (status == google.maps.places.PlacesServiceStatus.OK) {
        let reviewEl = document.querySelector('.reviews');
        for (let review of place.reviews){
          let li = document.createElement('li');
          li.innerHTML = `<div>Author: ${review.author_name}</div>
                          <em>${review.text}</em>
                          <div>Rating: ${review.rating} star(s)</div>`;
          reviewEl.appendChild(li);
        }
      }
    });
  }
}
* {
  box-sizing: border-box;
}

#map {
  width: 500px;
  height: 400px;
}

.reviews {
  padding:0;
  list-style:none;
}

.reviews li+li {
  margin-top: 1em;
  padding-top: 1em;
  border-top: 1px solid black;
}
.reviews em{display:block;margin:0.3em 0;}
<div id="map"></div>
<ul class="reviews"></ul>

<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDbDfZUthAGL2BW3jg9xhWglf6HLpJQ1AU&callback=initMap&libraries=places"
    async defer></script>
like image 115
Gabriele Petrioli Avatar answered Oct 18 '22 01:10

Gabriele Petrioli


You can use the Google Maps API:

https://maps.googleapis.com/maps/api/place/details/json?place_id=<place_id>&fields=reviews&key=<api_key>

More here: https://developers.google.com/places/web-service/details#PlaceDetailsResults

like image 25
dom Avatar answered Oct 18 '22 03:10

dom