管理实时通知
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在 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 指南设置您的应用。
- 在 Cloud Pub/Sub 项目中创建主题,并记下所创建主题的名称。
- 为 mybusiness-api-pubsub@system.gserviceaccount.com 授予不低于
pubsub.topics.publish
的权限。
- 按照订阅者概览指南设置推送通知或拉取通知。
- 如需接收通知,请调用 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
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[[["\u003cp\u003eThe My Business Notifications API uses Cloud Pub/Sub to deliver notifications about various business events, such as new reviews, Q&As, and location updates.\u003c/p\u003e\n"],["\u003cp\u003eTo receive notifications, you must set up a Cloud Pub/Sub topic, grant necessary permissions, and link your Business Profile account to the topic using the API.\u003c/p\u003e\n"],["\u003cp\u003eYou can manage your notification settings using the API to retrieve, update (including setting a new topic or deleting the setting), or delete them.\u003c/p\u003e\n"],["\u003cp\u003eThe API provides endpoints for retrieving, updating, and deleting notification settings associated with your Business Profile account.\u003c/p\u003e\n"],["\u003cp\u003eRefer to the provided links for detailed instructions on setting up Cloud Pub/Sub and using the My Business Notifications API.\u003c/p\u003e\n"]]],[],null,["# Manage real-time notifications\n\n\u003cbr /\u003e\n\nIn the My Business Notifications API, notifications are published in\nthe [Cloud Pub/Sub](https://cloud.google.com/pubsub/) service. After\nyou set up Cloud Pub/Sub and create a topic, you can perform the following\noperations on notifications:\n\n- [Retrieve notification settings.](#retrieve_notification_settings)\n- [Update notification settings.](#update_notification_settings)\n- [Delete notification settings.](#delete_notification_settings)\n\nNew or updated reviews, questions and answers, media uploads,\nGoogle updates for review, location state changes, and more are supported.\nThe [NotificationType](/my-business/reference/notifications/rest/v1/NotificationSetting#NotificationType) object\nlists and describes the available notification types.\n\nBefore you begin\n----------------\n\nTo use the My Business Notifications API, register your application and obtain\nOAuth 2.0 credentials. For details on how to get started with the API,\nsee [Basic setup](/my-business/content/basic-setup).\n\nCloud Pub/Sub setup\n-------------------\n\nTo set up API notifications with\n[Cloud Pub/Sub](https://cloud.google.com/pubsub/), perform the following steps:\n\n1. Follow the Cloud Pub/Sub guide to [set up your application](https://cloud.google.com/pubsub/docs/quickstart-client-libraries).\n2. [Create a topic](https://cloud.google.com/pubsub/docs/admin#create_a_topic) in your Cloud Pub/Sub project and note the name of the created topic.\n3. Give at least [`pubsub.topics.publish`](https://cloud.google.com/pubsub/docs/access-control#tbl_roles) permissions to mybusiness-api-pubsub@system.gserviceaccount.com.\n4. Follow the [Subscriber overview](https://cloud.google.com/pubsub/docs/subscriber) guide to set up either push or pull notifications.\n5. To receive notifications, call the [`accounts.updateNotificationSetting`](/my-business/reference/notifications/rest/v1/accounts/updateNotificationSetting) endpoint in the My Business Notifications API. In the call, use the topic name you created in Cloud Pub/Sub to link your Business Profile account to the topic.\n6. (Optional) Repeat step 5 for each Business Profile account that you want to receive notifications for.\n\nRetrieve notification settings\n------------------------------\n\nThe [`accounts.getNotificationSetting`](/my-business/reference/notifications/rest/v1/accounts/getNotificationSetting)\nendpoint returns the current Cloud Pub/Sub notification settings for an\naccount. The following table shows how to call it:\nHTTP \n\n```\nGET\nhttps://mybusinessnotifications.googleapis.com/v1/accounts/{accountId}/notificationSetting\n```\n\nUpdate notification settings\n----------------------------\n\nThe [`accounts.updateNotificationSetting`](/my-business/reference/notifications/rest/v1/accounts/updateNotificationSetting)\nendpoint updates the Cloud Pub/Sub notification settings associated with an\naccount. The following table shows how to call it:\nHTTP \n\n```\nPATCH\nhttps://mybusinessnotifications.googleapis.com/v1/accounts/{accountId}/notificationSetting?updateMask={commaSeparatedFieldsToUpdate}\n\n{\n pubsubTopic: your/pubsub/topicName\n}\n```\n\nDelete notification settings\n----------------------------\n\nCalling the [`accounts.updateNotificationSetting`](/my-business/reference/notifications/rest/v1/accounts/updateNotificationSetting)\nwith an empty `pubsubTopic` deletes the Cloud Pub/Sub notification settings from an account.\nThe following table shows how to call it:\nHTTP \n\n```\nPATCH\nhttps://mybusinessnotifications.googleapis.com/v1/accounts/{accountId}/notificationSetting?updateMask=pubsubTopic\n```"]]