用于从 Google for business 获取所有评论和评级的 API

Posted

技术标签:

【中文标题】用于从 Google for business 获取所有评论和评级的 API【英文标题】:API to get all the reviews and rating from Google for business 【发布时间】:2017-10-08 17:27:20 【问题描述】:

我正在使用 Google Maps API 来获取公司的评论和评级。

第 1 步:获取参考 ID 的 HTTP 请求。

$url = 'https://maps.googleapis.com/maps/api/place/textsearch/json?query='.<CompanyName>.'&sensor=true&key='.<apikey>;

在 HTTP 请求之后,我得到了业务的 referenceId。

第 2 步:获取评论的 HTTP 请求。

$url = 'https://maps.googleapis.com/maps/api/place/details/json?reference='.<referenceId>.'&key='.<apiKey>

通过以上内容,我获得了“最有帮助的评论”和最多 5 条评论。

所以我想获取所有评论或最新评论。需要加参数吗?

【问题讨论】:

这里有更新吗? 【参考方案1】:

有一个像 SerpApi 这样的第三方解决方案,您可以使用它来获取任何地方的所有评论。这是一个免费试用的付费 API。

每页包含 10 个结果。要实现分页,只需使用定义结果偏移量的start 参数(例如,0(默认)是结果的第一页,10 是结果的第二页,20 是结果的第三页结果等)

require 'path/to/google_search_results';

$query = [
  "engine" => "google_maps_reviews",
  "place_id" => "0x89c259a61c75684f:0x79d31adb123348d2",
  "api_key" => "SECRET_API_KEY"
];

$search = new GoogleSearch();
$results = $search->json($query);
$reviews = $result->reviews;

示例输出:

"reviews": [
  
    "user": 
      "name": "Waylon Bilbrey",
      "link": "https://www.google.com/maps/contrib/107691056156160235121?hl=en-US&sa=X&ved=2ahUKEwiUituIlpTvAhVYCc0KHbvTCrgQvvQBegQIARAx",
      "thumbnail": "https://lh3.googleusercontent.com/a-/AOh14GjOj6Wjfk1kSYjhvH7WIBNMdl4nPj6FvUhvYcR6=s40-c0x00000000-cc-rp",
      "reviews": 1
    ,
    "rating": 4,
    "date": "a week ago",
    "snippet": "I've been here multiple times. The coffee itself is just average to me. The service is good (the people working are nice). The aesthetic is obviously what brings the place some fame. A little overpriced (even for NY). A very small cup for $6 where I feel like the price comes from the top rainbow foam decor , when I'm going to cover it anyways. If it's for an insta pic then it may be worth it?"
  ,
  
    "user": 
      "name": "Amber Grace Sale",
      "link": "https://www.google.com/maps/contrib/106390058588469541899?hl=en-US&sa=X&ved=2ahUKEwiUituIlpTvAhVYCc0KHbvTCrgQvvQBegQIARA7",
      "thumbnail": "https://lh3.googleusercontent.com/a-/AOh14Gj84nHu_9V_0V4yRbZcr-8ZTYAHua6gUBP8fC7W=s40-c0x00000000-cc-rp-ba3",
      "local_guide": true,
      "reviews": 33,
      "photos": 17
    ,
    "rating": 5,
    "date": "2 years ago",
    "snippet": "They really take pride in their espresso roast here and the staff is extremely knowledgeable on the subject. It’s also a GREAT place to do work although a table is no guarantee; you might have to wait for a bit. My almond milk cappuccino was very acidic at the end which wasn’t expected but I could still tell the bean was high quality. Their larger lattés they put in a tall glass cup which looks really really cool. Would definitely go again.",
    "likes": 2,
    "images": [
      "https://lh5.googleusercontent.com/p/AF1QipMup24_dHrWtNN4ZD70EPsiRMf_tykcUkPw6A1H=w100-h100-p-n-k-no"
    ]
  ,
  
    "user": 
      "name": "Kelvin Petar",
      "link": "https://www.google.com/maps/contrib/100859090874785206875?hl=en-US&sa=X&ved=2ahUKEwiUituIlpTvAhVYCc0KHbvTCrgQvvQBegQIARBG",
      "thumbnail": "https://lh3.googleusercontent.com/a-/AOh14GhdIvUDamzfPqbYIpwhnGJV2XWSi77iVXfEsiKS=s40-c0x00000000-cc-rp",
      "reviews": 3
    ,
    "rating": 4,
    "date": "3 months ago",
    "snippet": "Stumptown Cafe is the perfect place to work or catch up with friends. Never too loud, never too dead. Their lattes and deliciously addicting and the toasts are tasty as well. Wifi is always fast, which is a huge plus! The staff are the friendliest, I highly recommend this place!"
  ,
  ...
]

您可以查看documentation了解更多详情。

免责声明:我在 SerpApi 工作。

【讨论】:

【参考方案2】:

使用位置的 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'];

【讨论】:

不是最后 5 条,它返回随机 5 条评论。 虽然它似乎应该有效,但显然它已成为一项付费服务​​,因为我收到以“您必须启用计费...”开头的消息【参考方案3】:

目前,Google 最多只提供五个结果,他们在文档中提到了这一点。 如果您想获得对您自己的财产/地点或业务的评论,您可以选择我的业务,​​但我认为他们使该 API 关闭了。

编辑:如果您仍想获取所有评论,您可以使用 html 解析器并解析所有评论(我不了解 Google 的数据政策,但您绝对可以从网站上抓取所有内容)

【讨论】:

有没有第三方服务可以提供所有的评论? 任何帮助谢谢magento.stackexchange.com/q/335542/57334【参考方案4】:

如果您想获得所有评论,您应该需要使用 Google My Business API。

这是另一个不同的 API,您应该向 Google 请求该地点的属性。

https://developers.google.com/my-business/content/review-data#list_all_reviews

【讨论】:

其实我想要任何一家公司的所有评论和评级,而不是单个公司。 公司名称是动态的。 如果该地点显然不是您的,您将无法访问该地点的 My Business API。 Google Maps API 最多只能提供 5 条评论。您可以使用语言参数,但对于您请求的每种语言,您只会收到 5 条评论。 developers.google.com/places/web-service/details?hl=en-419 使用地图 API 很抱歉,这是不可能的。检查我在上一条评论中放置的 API 链接。它说reviews[] a JSON array of up to five reviews 哎呀,有什么想法可以得到所有的评论吗?

以上是关于用于从 Google for business 获取所有评论和评级的 API的主要内容,如果未能解决你的问题,请参考以下文章

Lync 项目经验-20-Skype for Business for Android-下载到电脑

WinUI 3.0 - 为啥 UWP 项目要求 MS Edge for Business 用于 WebView2

8 Reasons why SharePoint is Bad for Your Business 8个理由告诉你,为什么SharePoint对你的业务有害

从控制台应用程序使用 Skype for Business Online 发送 IM

Skype for Business核心/插件Java API

PowerBI从Lync或Skype for Business数据库中分析数据和KPI展现