I am using the Google Maps API to get the reviews and ratings for a company.
Step 1: HTTP Request to get the reference Id.
$url = 'https://maps.googleapis.com/maps/api/place/textsearch/json?query='.<CompanyName>.'&sensor=true&key='.<apikey>;
After HTTP request I am getting referenceId of business.
Step 2: HTTP request to get the reviews.
$url = 'https://maps.googleapis.com/maps/api/place/details/json?reference='.<referenceId>.'&key='.<apiKey>
With the above, I am getting the "most helpful reviews" and a maximum of 5 reviews.
So I want to get all the reviews or the latest reviews. Do I need to add a parameter?
You should need to use the Google My Business API if you want to get all the reviews.
It's another different API, and you should request from Google the property of the place.
https://developers.google.com/my-business/content/review-data#list_all_reviews
Other simple method to get the 5 last rewiews with the place_id of the location (you can find it here : https://developers.google.com/places/place-id)
$url = "https://maps.googleapis.com/maps/api/place/details/json?key=Yourkey&placeid=YourplaceID";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($ch);
$res = json_decode($result,true);
$reviews = $res['result']['reviews'];
Currently, Google provides up to five results only, they mentioned it in their documentation. If you want to get reviews for your own property/place or business you can go for my business but I think they made that API closed one.
Edit: If you still want to fetch all reviews you can use an HTML parser and parse all the reviews(i don't know about Google's data policy, but you can definitely scrape everything from a site)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With