我想阅读谷歌为特定帐户返回的通知列表。看来我的旧程序无法正常工作,而且我找不到新 API 的示例。回到代码,我们假设
mybusinessNotif
是 MyBusinessNotificationSettings
类型的初始值设定项,它也负责凭证:
List<String> notificationTypes = Arrays.asList(
"GOOGLE_UPDATE", "NEW_REVIEW", "UPDATED_REVIEW", "NEW_QUESTION",
"UPDATED_QUESTION", "NEW_ANSWER", "UPDATED_ANSWER"
);
GetNotificationSetting getSettings = mybusiness.accounts().getNotificationSetting(accountId+"/notificationSetting");
NotificationSetting currentSettings = getSettings.execute();
String pubSubTopic = "projects/"+projectId+"/topics/notifications";
currentSettings.setNotificationTypes(notificationTypes).setPubsubTopic(pubSubTopic);
UpdateNotificationSetting updateRequest = mybusiness.accounts().updateNotificationSetting(accountId + "/notificationSetting", currentSettings);
NotificationSetting updatedSettings = updateRequest.execute();
System.out.println("Notification settings updated: " + updatedSettings);
错误是
发布https://mybusinessnotifications.googleapis.com/v1/accounts/XXXXXXXXX/notificationSetting { “代码”:400, “细节” : [ { “@type”:“type.googleapis.com/google.rpc.BadRequest” }], “错误”:[ { “域”:“全球”, "message" : "请求包含无效参数。", “原因”:“错误请求” }], "message" : "请求包含无效参数。", “状态”:“INVALID_ARGUMENT” }
我在文档中没有找到任何示例来了解语法是什么:[https://developers.google.com/my-business/reference/notifications/rest/v1/NotificationSetting] 据记载,如果我想查看通知,我需要设置字符串类型的
pubsubTopic
:
可选。当此帐户管理的位置更新时将收到通知的 Google Pub/Sub 主题。如果未设置,则不会发布任何通知。 帐户 [电子邮件受保护] 必须至少具有 Pub/Sub 主题的发布权限。
这个所谓的 pubsub 主题应该如何设置? 有没有使用过这个 API 的人可以帮我一下吗?
使用Java客户端库,更新工作如下:
List<String> notificationTypesList = Arrays.asList("GOOGLE_UPDATE", "NEW_REVIEW",
"UPDATED_REVIEW");
NotificationSetting content = new NotificationSetting()
.setNotificationTypes(notificationTypesList)
.setPubsubTopic(pubSubTopic);
UpdateNotificationSetting updateNotificationSetting = myBusinessNotificationSettings
.accounts().updateNotificationSetting(notificationSettingPath, content)
.setUpdateMask("notificationTypes,pubsubTopic");
通过 OAuth Playground,等效请求将是:
PATCH /v1/accounts/123456789012345678901/notificationSetting?updateMask=notificationTypes,pubsubTopic
身体:
{
"notificationTypes": [ "GOOGLE_UPDATE", "NEW_REVIEW", "UPDATED_REVIEW" ],
"pubsubTopic": "projects/my-gcp-project/topics/my-topic-name"
}
如果您有权访问 GBP API 和该位置组,并且有一个涉及该主题的 GCP 项目,那么这肯定可行。