我正在尝试使用以下代码订阅,以便在每次发布针对企业的新评论时接收通知。
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
需要设置 topicName
和 notificationTypes
。 name
字段将被忽略。请参阅https://developers.google.com/my-business/reference/rest/v4/Notifications
关于java - Google Business Api - Pub Sub 更新通知设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50059306/