在 My Business Notifications API 中,通知會發布至 Cloud Pub/Sub 服務。設定 Cloud Pub/Sub 並建立主題後,您可以對通知執行下列操作:
支援新評論或更新評論、媒體上傳、待審查的 Google 資訊更新、地點狀態變更等。NotificationType 物件會列出並說明可用的通知類型。
事前準備
如要使用 My Business Notifications API,請註冊應用程式並取得 OAuth 2.0 憑證。如要進一步瞭解如何開始使用 API,請參閱「基本設定」。
Cloud Pub/Sub 設定
如要使用 Cloud Pub/Sub 設定 API 通知,請按照下列步驟操作:
- 請按照 Cloud Pub/Sub 指南設定應用程式。
- 在擁有 OAuth 2.0 憑證的 Google Cloud 專案中建立主題,並記下建立的主題名稱。如果通知消費者在其他 Google Cloud 專案中執行,請參閱「在其他雲端專案中接收通知」。
- 請至少將
pubsub.topics.publish權限授予 mybusiness-api-pubsub@system.gserviceaccount.com。 - 請按照訂閱者總覽指南,設定推送或提取通知。
- 如要接收通知,請呼叫 My Business Notifications API 中的
accounts.updateNotificationSetting端點。在呼叫中,使用您在 Cloud Pub/Sub 建立的主題名稱,將商家檔案帳戶連結至主題。 - (選用) 針對要接收通知的每個商家檔案帳戶,重複執行步驟 5。
擷取通知設定
accounts.getNotificationSetting 端點會傳回帳戶目前的 Cloud Pub/Sub 通知設定。下表說明如何呼叫:
GET
https://mybusinessnotifications.googleapis.com/v1/accounts/{accountId}/notificationSetting
更新通知設定
accounts.updateNotificationSetting 端點會更新與帳戶相關聯的 Cloud Pub/Sub 通知設定。下表說明如何呼叫:
PATCH
https://mybusinessnotifications.googleapis.com/v1/accounts/{accountId}/notificationSetting?updateMask={commaSeparatedFieldsToUpdate}
{
pubsubTopic: your/pubsub/topicName
}
刪除通知設定
使用空白的 pubsubTopic 呼叫 accounts.updateNotificationSetting,會從帳戶中刪除 Cloud Pub/Sub 通知設定。下表說明如何呼叫:
PATCH
https://mybusinessnotifications.googleapis.com/v1/accounts/{accountId}/notificationSetting?updateMask=pubsubTopic