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

旧巷老猫 提交于 2020-01-22 13:32:26

问题


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?


回答1:


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




回答2:


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)




回答3:


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'];


来源:https://stackoverflow.com/questions/43886124/api-to-get-all-the-reviews-and-rating-from-google-for-business

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!