Google Business Api - Pub Sub更新通知设置

时间:2018-04-27 09:26:09

标签: java google-cloud-pubsub google-client google-my-business-api

我尝试订阅每次使用以下代码为企业发布新评价时都会收到通知。

private static final String topicName = "projects/myproject-12345/topics/business-review";
MyBusiness myBusiness = GMBFactory.getMyBusiness();
    MyBusiness.Accounts.List accountsList = myBusiness.accounts().list();
    ListAccountsResponse response = accountsList.execute();
    List<Account> accounts = response.getAccounts();
    for (Account account : accounts) {
        Notifications notification = new Notifications().setName(topicName);
        UpdateNotifications updateNotification = myBusiness.accounts().updateNotifications(account.getName() + "/notifications",
                notification);
        updateNotification.execute();
    }

当我尝试执行代码时,我收到以下错误。

com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
  "code" : 400,
  "errors" : [ {
  "domain" : "global",
  "message" : "Request contains an invalid argument.",
  "reason" : "badRequest"
} ],
"message" : "Request contains an invalid argument.",
"status" : "INVALID_ARGUMENT"
}

有人可以告诉我我做错了吗?

- 编辑 -

MyBusiness myBusiness = GMBFactory.getMyBusiness();
    MyBusiness.Accounts.List accountsList = myBusiness.accounts().list();
    ListAccountsResponse response = accountsList.execute();
    List<Account> accounts = response.getAccounts();
    for (Account account : accounts) {
        Notifications notification = new Notifications();
        notification.setTopicName(topicName);
        notification.setName("review");
        UpdateNotifications updateNotification = myBusiness.accounts().updateNotifications(account.getName() + "/notifications",
                notification);
        updateNotification.execute();
    }

1 个答案:

答案 0 :(得分:1)

Notifications要求设置notificationTypesnamelet numDoubled = num + (noise ? weighting : 0.0) 字段将被忽略。见https://developers.google.com/my-business/reference/rest/v4/Notifications