php 用于从 Google for business 获取所有评论和评级的 API
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43886124/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
API to get all the reviews and rating from Google for business
提问by Maneesh Rao
I am using the Google Maps API to get the reviews and ratings for a company.
我正在使用 Google Maps API 来获取公司的评论和评级。
Step 1: HTTP Request to get the reference Id.
第 1 步:HTTP 请求以获取参考 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.
在 HTTP 请求之后,我得到了业务的 referenceId。
Step 2: HTTP request to get the reviews.
第 2 步:获取评论的 HTTP 请求。
$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.
有了上述内容,我得到了“最有帮助的评论”和最多 5 条评论。
So I want to get all the reviews or the latest reviews. Do I need to add a parameter?
所以我想获得所有评论或最新评论。我需要添加参数吗?
采纳答案by NetVicious
You should need to use the Google My Business API if you want to get all the reviews.
如果您想获得所有评论,您应该需要使用 Google My Business API。
It's another different API, and you should request from Google the property of the place.
这是另一个不同的 API,您应该向 Google 请求该地点的财产。
https://developers.google.com/my-business/content/review-data#list_all_reviews
https://developers.google.com/my-business/content/review-data#list_all_reviews
回答by Dorian
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)
使用位置的 place_id 获取最后 5 次回访的其他简单方法(您可以在此处找到它: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'];
回答by jNambiar
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.
目前,Google 最多只提供五个结果,他们在文档中提到了这一点。如果您想获得对您自己的财产/地点或企业的评论,您可以去我的企业,但我认为他们使该 API 关闭了。
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)
编辑:如果您仍然想获取所有评论,您可以使用 HTML 解析器并解析所有评论(我不了解 Google 的数据政策,但您绝对可以从网站上抓取所有内容)