【问题标题】:How to publish my Google Business reviews updates to my topic如何将我的 Google 商家评论更新发布到我的主题
【发布时间】:2021-02-26 03:01:38
【问题描述】:
【问题讨论】:
标签:
google-cloud-pubsub
google-my-business-api
【解决方案1】:
accounts.updateNotifications 是用于设置通知的管理 API,它不是用于订阅的推送端点。您将用于设置此类通知的过程是:
- 创建 Pub/Sub 主题。假设它是
projects/my-project/topics/my-topic。
- 创建一个Cloud Function with a Pub/Sub trigger。您可以在Cloud Console 中执行此操作。选择“Cloud Pub/Sub”作为触发类型,并选择您在步骤 1 中创建的主题作为主题。这将创建一个推送订阅,每次消息通过时都会触发 Cloud Function。
- 以
Notifications 对象为主体向https://mybusiness.googleapis.com/v4/accounts/{accountId}/notifications 发出请求,其中acccountId 是您的帐户ID。 topicName 将是在步骤 1 中创建的主题名称(在本示例中为 projects/my-project/topics/my-topic),notificationTypes 将是包含单个项目 NEW_REVIEW 的列表。您可以通过 curl 请求执行此操作,例如:
curl -X https://mybusiness.googleapis.com/v4/accounts/{accountId}/notifications -H "Content-Type: application/json" -d '{"name": "my-name","topicName": "projects/my-project/topics/my-topic","notificationTypes": ["NEW_REVIEW"]}'
尽管您需要通过身份验证才能发出该请求。
如果该调用成功返回,则表示您的通知已正确设置,并且您的 Cloud Function 现在应该在您每次获得新评论时触发。