1

我正在尝试订阅 Google 我的商家帐户,以便在每次发布或更新新评论时接收通知。我在这里关注 Google 文档https://developers.google.com/my-business/reference/rest/v4/accounts/updateNotifications并使用来自 github 的 Google php 包装器 MyBusiness.php。

我通过 Goggle Cloud 控制台创建了主题 gmn-notification 和订阅。我还按照 Goggle 文档的建议将本主题中的 Pub/Sub 发布者角色分配给了 mybusiness-api-pubsub@system.gserviceaccount.com。

这是我的代码的相关摘录

$client = new Google_Client();
...
...
$mybusinessService = new Google_Service_Mybusiness($client);
$accounts = $mybusinessService->accounts;
$accountsList = $accounts->listAccounts()->getAccounts();
foreach ($accountsList as $accKey => $account) {
try
{
    $n=new Google_Service_MyBusiness_Notifications();
    $n->setNotificationTypes(['NEW_REVIEW', 'UPDATED_REVIEW']);
    $n->setTopicName("gmn-notification");
    $nam=$account->name."/notifications";
    $n->setName($nam);
    $notivication=$accounts->updateNotifications($nam,$n);
    error_log("notification=".print_r($notification,1));
} catch(Exception $e)
{
    error_log(print_r($e->getMessage(),1));
}

我看到,Google 在内部发送了以下看起来不错的 PUT 请求

method=PUT
target=/v4/accounts/112497043970166515141/notifications
uri=https://mybusiness.googleapis.com/v4/accounts/112497043970166515141/notifications
body={"name":"accounts\/112497043970166515141\/notifications","notificationTypes":["NEW_REVIEW","UPDATED_REVIEW"],"topicName":"gmn-notification"}

我收到以下异常

{
 "error": {
   "code": 400,
   "message": "Request contains an invalid argument.",
   "errors": [
     {
       "message": "Request contains an invalid argument.",
       "domain": "global",
       "reason": "badRequest"
     }
   ],
   "status": "INVALID_ARGUMENT"
 }
}

我想知道是否有人可以提供帮助。

4

0 回答 0