6

我正在使用 Google MyBsiness API 来获取所有业务评论。但我无法熟悉 MYBusiness 中的 PHP 语法和 GET、POST 方法。

在誓言之后,这是我用来获取评论的代码

$mybusinessService = new Google_Service_Mybusiness($client);
$accessToken = file_get_contents($credentialsPath);

$reviews = $mybusinessService->accounts_locations_reviews;
echo '<pre>';print_r($reviews->get('ArtechDev'));exit;

但我收到错误 404(致命错误:带有消息的未捕获异常“Google_Service_Exception”)

我确信我不知道如何传递参数以及它需要哪些东西。我以具有“ArtechDev”位置的帐户登录,请告诉我在哪里可以打电话

https://mybusiness.googleapis.com/v3/accounts/account_name/locations/location_name/reviews

谢谢

4

2 回答 2

8

我希望你很久以前就找到了你的问题的答案,无论如何我会留下这个希望能帮助别人。

/*$accounts previusly populate*/
/*(GMB - v4)*/
$credentials_f = "google_my_business_credentials_file.json";
$client = new Google_Client();
$client->setApplicationName($aplicattion_name);
$client->setDeveloperKey($developer_key);
$client->setAuthConfig($credentials_f);  
$client->setScopes("https://www.googleapis.com/auth/plus.business.manage");
$client->setSubject($accounts->email);   
$token = $client->refreshToken($accounts->refresh_token);
$client->authorize();

$locationName = "accounts/#######/locations/########";

$mybusinessService = new Google_Service_Mybusiness($client);

$reviews = $mybusinessService->accounts_locations_reviews;

do{
    $listReviewsResponse = $reviews->listAccountsLocationsReviews($locationName, array('pageSize' => 100,
                        'pageToken' => $listReviewsResponse->nextPageToken));

    $reviewsList = $listReviewsResponse->getReviews();
    foreach ($reviewsList as $index => $review) {
        /*Accesing $review Object

        * $review->createTime;
        * $review->updateTime;
        * $review->starRating;
        * $review->reviewer->displayName;
        * $review->reviewReply->comment;
        * $review->getReviewReply()->getComment();
        * $review->getReviewReply()->getUpdateTime();
        */

    }

}while($listReviewsResponse->nextPageToken);
于 2018-02-22T14:26:14.950 回答
-1

$acounts 来自:

$mybusinessService = new Google_Service_MyBusiness(...);
$accounts = $mybusinessService->accounts;
于 2020-01-28T01:38:24.797 回答