如何设置 pubsubTopic 以便使用 java 中的 mybusinessnotifications.googleapis.com 列出 google 帐户中的通知
How to set pubsubTopic in order to list the notifications in a google account using mybusinessnotifications.googleapis.com in java
我想阅读 google returns 特定帐户的通知列表。看来我的旧程序不工作了,我找不到新的例子API。回到代码,我们假设 mybusinessNotif
是类型 MyBusinessNotificationSettings
的初始值设定项,它还处理凭据:
MyBusinessNotificationSettings.Accounts.GetNotificationSetting request =mybusinessNotif.accounts().getNotificationSetting(name+"/notificationSetting");
NotificationSetting response=request.execute();
List<String> notifTypeList=response.getNotificationTypes();
System.out.println("response="+response.toPrettyString());
if(notifTypeList!=null && !notifTypeList.isEmpty()) {
for(String st:notifTypeList) {
System.out.println("notifTypeList ==="+ st);
}
}
Google 没有通过通知进行响应,唯一的响应是帐户名:
response={
"name" : "accounts/XXXXX/notificationSetting"
}
我没有在文档中找到任何示例来查看语法是什么:[https://developers.google.com/my-business/reference/notifications/rest/v1/NotificationSetting]
上面写道,如果我想查看通知,我需要设置 pubsubTopic
类型的字符串:
Optional. The Google Pub/Sub topic that will receive notifications when locations managed by this account are updated. If unset, no notifications will be posted.
The account mybusiness-api-pubsub@system.gserviceaccount.com must have at least Publish permissions on the Pub/Sub topic.
这个所谓的pubsub topic应该怎么设置?
有人用过这个 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 项目,那么这绝对有效。
我想阅读 google returns 特定帐户的通知列表。看来我的旧程序不工作了,我找不到新的例子API。回到代码,我们假设 mybusinessNotif
是类型 MyBusinessNotificationSettings
的初始值设定项,它还处理凭据:
MyBusinessNotificationSettings.Accounts.GetNotificationSetting request =mybusinessNotif.accounts().getNotificationSetting(name+"/notificationSetting");
NotificationSetting response=request.execute();
List<String> notifTypeList=response.getNotificationTypes();
System.out.println("response="+response.toPrettyString());
if(notifTypeList!=null && !notifTypeList.isEmpty()) {
for(String st:notifTypeList) {
System.out.println("notifTypeList ==="+ st);
}
}
Google 没有通过通知进行响应,唯一的响应是帐户名:
response={ "name" : "accounts/XXXXX/notificationSetting" }
我没有在文档中找到任何示例来查看语法是什么:[https://developers.google.com/my-business/reference/notifications/rest/v1/NotificationSetting]
上面写道,如果我想查看通知,我需要设置 pubsubTopic
类型的字符串:
Optional. The Google Pub/Sub topic that will receive notifications when locations managed by this account are updated. If unset, no notifications will be posted. The account mybusiness-api-pubsub@system.gserviceaccount.com must have at least Publish permissions on the Pub/Sub topic.
这个所谓的pubsub topic应该怎么设置? 有人用过这个 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 项目,那么这绝对有效。