3

我们有一个管理多个位置的 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);
}

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

4

1 回答 1

0

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

// $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);
}

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

于 2021-01-08T08:36:50.650 回答