我有这段代码希望获取Google mybusiness的评论:
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . realpath($_SERVER["DOCUMENT_ROOT"]) . '/google-api/account-service-mybusiness.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setScopes("https://www.googleapis.com/auth/plus.business.manage");
$client->setIncludeGrantedScopes(true);
$user_to_impersonate = "xxxxxx@gmail.com";
$client->setSubject($user_to_impersonate);
$client->authorize();
$locationName = "accounts/xxxxxxxxxx/locations/xxxxxxxxxx";
$myBusinessService = new Google_Service_Mybusiness($client);
$reviews = $myBusinessService->accounts_locations_reviews;
但是当我尝试进行评论时,出现此致命错误:
致命错误:未捕获的Google_Service_Exception:{“错误”: “ unauthorized_client”,“错误说明”:“客户端未经授权 使用此方法检索访问令牌。“} in /web/htdocs/www.locandadalmoccia.it/home/google-api/vendor/google/apiclient/src/Google/Http/REST.php:118 堆栈跟踪:#0 /web/htdocs/www.locandadalmoccia.it/home/google-api/vendor/google/apiclient/src/Google/Http/REST.php(94): Google_Http_REST :: decodeHttpResponse(Object(GuzzleHttp \ Psr7 \ Response), 对象(GuzzleHttp \ Psr7 \ Request),'Google_Service _...')#1 /web/htdocs/www.locandadalmoccia.it/home/google-api/vendor/google/apiclient/src/Google/Task/Runner.php(176): Google_Http_REST :: doExecute(Object(GuzzleHttp \ Client), 对象(GuzzleHttp \ Psr7 \ Request),'Google_Service _...')#2 /web/htdocs/www.locandadalmoccia.it/home/google-api/vendor/google/apiclient/src/Google/Http/REST.php(58): Google_Task_Runner-> run()#3 /web/htdocs/www.locandadalmoccia.it/home/google-api/vendor/google/apiclient/src/Google/Client.php(798): Google_Http_REST :: execute(Object(Guzzl in /web/htdocs/www.locandadalmoccia.it/home/google-api/vendor/google/apiclient/src/Google/Http/REST.php 在第118行
somneone可以帮助我解决吗?