管理即時通知

在 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 通知,請執行下列步驟:

  1. 請按照 Cloud Pub/Sub 指南設定應用程式
  2. 在 Cloud Pub/Sub 專案中建立主題,並記下建立的主題名稱。
  3. 將至少 pubsub.topics.publish 權限授予 mybusiness-api-pubsub@system.gserviceaccount.com。
  4. 請按照訂閱者總覽指南設定推播或拉取通知。
  5. 如要接收通知,請呼叫 My Business Notifications API 中的 accounts.updateNotificationSetting 端點。在呼叫中,請使用您在 Cloud Pub/Sub 中建立的主題名稱,將商家檔案帳戶連結至主題。
  6. (選用) 針對要接收通知的每個商家檔案帳戶,重複執行步驟 5。

擷取通知設定

accounts.getNotificationSetting 端點會傳回帳戶目前的 Cloud Pub/Sub 通知設定。下表說明如何呼叫此方法:

HTTP
GET
https://mybusinessnotifications.googleapis.com/v1/accounts/{accountId}/notificationSetting

更新通知設定

accounts.updateNotificationSetting 端點會更新與帳戶相關聯的 Cloud Pub/Sub 通知設定。下表說明如何呼叫此方法:

HTTP
PATCH
https://mybusinessnotifications.googleapis.com/v1/accounts/{accountId}/notificationSetting?updateMask={commaSeparatedFieldsToUpdate}

{
  pubsubTopic: your/pubsub/topicName
}

刪除通知設定

呼叫 accounts.updateNotificationSetting 時,如果 pubsubTopic 為空白,系統就會刪除帳戶中的 Cloud Pub/Sub 通知設定。下表說明如何呼叫此方法:

HTTP
PATCH
https://mybusinessnotifications.googleapis.com/v1/accounts/{accountId}/notificationSetting?updateMask=pubsubTopic