Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API to get all the reviews and rating from Google for business

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?

like image 489
Maneesh Rao Avatar asked May 10 '17 07:05

Maneesh Rao


3 Answers

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

like image 136
NetVicious Avatar answered Dec 28 '22 09:12

NetVicious


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'];
like image 40
Dorian Avatar answered Dec 28 '22 09:12

Dorian


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)

like image 40
jNambiar Avatar answered Dec 28 '22 09:12

jNambiar