在java中使用mybusinessnotifications.googleapis.com时如何设置pubsubTopic以摆脱SHARES_PUBSUB_TOPIC_MESSAGE_ACROSS_VERSIONS

问题描述 投票:0回答:1

我想阅读谷歌为特定帐户返回的通知列表。看来我的旧程序无法正常工作,而且我找不到新 API 的示例。 首先,我们需要设置我们感兴趣的通知类型。假设

mybusiness
MyBusinessNotificationSettings
类型的初始值设定项,它也负责凭据:

 public void setNotificationTypes(String accountId, String projectId) {
        try {
            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).setUpdateMask("pubsub_topic,notification_types");
            
            NotificationSetting updatedSettings = updateRequest.execute();


            System.out.println("Notification settings updated: " + updatedSettings);

        } catch (Exception e) {
            e.printStackTrace();
            
        }
    }

错误是

POST https://mybusinessnotifications.googleapis.com/v1/accounts/XXXXXXXXXXXX/notificationSetting?updateMask=pubsub_topic,notification_types { “代码”:400, “细节” : [ { "@type" : "type.googleapis.com/google.rpc.ErrorInfo", “原因”:“SHARES_PUBSUB_TOPIC_MESSAGE_ACROSS_VERSIONS” }], “错误”:[ { “域”:“全球”, "message" : "请求包含无效参数。", “原因”:“错误请求” }], "message" : "请求包含无效参数。", “状态”:“INVALID_ARGUMENT” }

我该如何处理

SHARES_PUBSUB_TOPIC_MESSAGE_ACROSS_VERSIONS
问题? 我已经检查了权限都正确并且notifications
topic
存在,我什至尝试创建一个新主题但结果没有改变。

有使用过这个 API 的人可以帮助我吗?

java google-cloud-pubsub google-my-business-api google-my-business
1个回答
2
投票

使用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 项目,那么这肯定可行。

© www.soinside.com 2019 - 2024. All rights reserved.