1

我想阅读谷歌为特定帐户返回的通知列表。看来我的旧程序不起作用,我找不到新 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字符串类型:

可选的。当此帐户管理的位置更新时将收到通知的 Google Pub/Sub 主题。如果未设置,则不会发布任何通知。帐户 mybusiness-api-pubsub@system.gserviceaccount.com 必须至少具有 Pub/Sub 主题的发布权限。

应该如何设置这个所谓的 pubsub 主题?有没有人使用过这个 API,可以帮我一把吗?

4

1 回答 1

1

使用 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 项目,那么这绝对应该有效。

于 2022-02-23T14:53:18.293 回答