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

标签 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();
    }

最佳答案

Notifications需要设置 topicNamenotificationTypesname 字段将被忽略。请参阅https://developers.google.com/my-business/reference/rest/v4/Notifications

关于java - Google Business Api - Pub Sub 更新通知设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50059306/

相关文章:

java - 当我在 Webdriver 中使用 Java 运行脚本时,我收到错误消息 "No alert is active"

java - 测量 Java 方法的执行时间

java - Kafka Streams 仅提交 KGroupedTable 的最新消息

firebase - Google Cloud Functions Cron 作业不起作用

ruby-on-rails - Google::Apis::AuthorizationError(未授权)

php 谷歌广告 api - unauthorized_client

java - 以正确的方式实现白板模式?

google-cloud-platform - 如何在重新启动之间保留 PubSub 模拟器主题/订阅

javascript - Google Pub/Sub 如何在 Pull 上设置读取超时

java - 无法使用我的服务对象连接到我的谷歌端点