1

我想知道如何使用 GMB API 来获取评论。根据谷歌文档,我们必须发出 GET 请求https://mybusiness.googleapis.com/v3/{name=accounts/*/locations/*}/reviews

但是{name=accounts/*/locations/*}我们可以从哪里获得帐户和位置的价值是什么意思。

这也需要 OAuth 2.0。如果我得到一个 access_token,那么 GET 请求将是这样的:- https://mybusiness.googleapis.com/v3/{name=accounts/*/locations/*}/reviews?access_token=token

这非常令人困惑。有人可以告诉我如何正确使用 GMB API 来获取谷歌评论。

4

2 回答 2

3

使用 Google OAuth 2 Playground 测试 Google 评论的获取

  1. 创建项目
    • Console.cloud.google.com
    • 以 {projectowner}@google.com 身份登录
    • 从标题的下拉列表中选择一个项目或单击新建项目
  2. 转到左侧菜单中的 API 和服务
  3. 启用 Google My Business API;这需要 Google 进行验证,可能需要几天时间。他们会给你发电子邮件。
  4. 转到developers.google.com/oauthplayground
  5. 使用设置工具,将 OAuth 流设置为客户端,然后单击使用您自己的 OAuth 凭据
  6. 从 console.developers.google.com/apis 获取客户端 ID 并将其粘贴到
  7. 将此纳入范围:https ://www.googleapis.com/auth/plus.business.manage并通过 {projectowner}@gmail.com 授权
  8. 交换令牌的验证码
  9. 要获取帐户名称:
  10. 要获取位置名称:
    • 将请求 URI 设置为https://mybusiness.googleapis.com/v4/accounts/ {paste account name here}/locations 其中 {paste ... here} 是您复制的帐户名称
    • 返回的 JSON 包含您的所有位置
    • 将包含引号和逗号的位置名称复制到临时持有文件中;下一步将在 JSON 数组中使用它们
  11. 获得多个地点的评论 将 Request URI 设置为https://mybusiness.googleapis.com/v4/accounts/ {account name here}/locations:batchGetReviews 和 Method to Post b. 将请求正文设置为 { "locationNames": [ "accounts/999999999999999999999/locations/88888888888888888888", "accounts/9999999999999999999999/locations/77777777777777777777", . . . “accounts/999999999999999999999/locations/11111111111111111111”],“pageSize”:200,“orderBy”:“updateTime desc”,“ignoreRatingOnlyReviews”:false }

使用您从位置 JSON 中为数组的每一行保存的帐户名称

  1. 如果总评论数超过 200 条,则必须将 "pageToken": string 添加到 JSON 正文中,其中 string 是前面 POST 中返回的值。
于 2019-05-15T19:25:42.783 回答
0

但是 {name=accounts/ /locations/ } 是什么意思,我们可以从哪里获得帐户和位置的值。

要获取此详细信息,请先使用以下 API ( https://mybusiness.googleapis.com/v4/accounts?access_token=#####)获取帐户

获得帐户列表后,在此 API 的响应中使用以下 API ( https://mybusiness.googleapis.com/v3/" + name + "/locations) 获取帐户位置列表,您将获得{name=accounts/*/locations/*}.

这也需要 OAuth 2.0。如果我得到一个 access_token,那么 GET 请求将是这样的:https://mybusiness.googleapis.com/v3/{name=accounts/*/locations/*}/reviews?access_token=token

对,那是正确的。

让我知道这项工作是否适合你。

于 2018-08-30T22:13:19.387 回答