【问题标题】:How to post a new answer to a question with Google My business API in PHP如何在 PHP 中使用 Google My business API 发布问题的新答案
【发布时间】:2019-09-24 12:57:16
【问题描述】:

我们有一个管理多个地点的“Google 我的商家”帐户。我想创建一个回答问题的界面。我的问题是我找不到如何检索当前位置的 Author 对象。

我尝试创建一个新的 Google_Service_MyBusiness_Author 对象并提交它,但它似乎不起作用。我正在使用 MyBusiness API 4.5

$author = new Google_Service_MyBusiness_Author();
$author->setDisplayName('location display name');
$author->setProfilePhotoUrl('someurl.jpg');
$author->setType('MERCHANT');

$answer = new Google_Service_MyBusiness_Answer();
$answer->setText($_POST['answerReplyText']);
$answer->setAuthor($author);

$postBody = new Google_Service_MyBusiness_UpsertAnswerRequest();
$postBody->setAnswer($answer);

try {
    $mybusinessService->accounts_locations_questions_answers->upsert($_POST['question_name'],$postBody);
}
catch(Exception $e) {
    var_dump($e);
}

我收到“请求包含无效参数”异常。我这样做对吗?我应该怎么做才能使我的答案有效?

【问题讨论】:

  • 我刚刚遇到了完全相同的问题,这曾经可以工作,但现在我只得到“无效参数”-异常。
  • 顺便说一句,答案的“作者”字段是“仅输出”,因此无需设置。
  • 我刚收到gmb api支持的答复,他们目前正在调查api中的一个问题。我向他们报告了这个问题,因为 api 请求不仅通过 php-sdk 失败,而且通过他们自己的 oauth2 游乐场失败。

标签: php google-my-business-api


【解决方案1】:

请通过删除仅输出字段尝试以下操作:

// $author = new Google_Service_MyBusiness_Author();
// $author->setDisplayName('location display name');
// $author->setProfilePhotoUrl('someurl.jpg');
// $author->setType('MERCHANT');

$answer = new Google_Service_MyBusiness_Answer();
$answer->setText($_POST['answerReplyText']);
// $answer->setAuthor($author);

$postBody = new Google_Service_MyBusiness_UpsertAnswerRequest();
$postBody->setAnswer($answer);

try {
    $mybusinessService->accounts_locations_questions_answers->upsert($_POST['question_name'],$postBody);
}
catch(Exception $e) {
    var_dump($e);
}

这对我很有效。希望这对您也有帮助。

【讨论】:

    猜你喜欢
    • 2017-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-09
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    相关资源
    最近更新 更多