【发布时间】:2019-11-18 23:21:17
【问题描述】:
我已经尝试了几个小时来解决这个问题,但我完全陷入困境。
我的业务 API 已获得批准,我创建了一个服务帐户并下载了 json 文件进行身份验证。
我正在使用google-api-php-client 和google-api-my-business-php-client,它提供了“Google_Service_MyBusiness”类供使用。
我的代码如下所示:-
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/google-api-my-business-php-client/MyBusiness.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS='.__DIR__.'/myfile.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
if (getenv('GOOGLE_APPLICATION_CREDENTIALS')) {
// use the application default credentials
$client->useApplicationDefaultCredentials();
} else {
echo missingServiceAccountDetailsWarning();
return;
}
$client->setApplicationName("my_app");
$client->addScope('https://www.googleapis.com/auth/plus.business.manage');
$service = new Google_Service_MyBusiness($client);
$accounts = $service->accounts;
$accountsList = $accounts->listAccounts()->getAccounts();
但我得到的只是
Google_Service_Exception: That’s an error. The requested URL <code>/v3/accounts</code> was not found on this server. That’s all we know.
我注意到文档现在是 v4,即 v4/accounts,这可能是问题吗?这些库过时了吗?如何使用 v3 检索帐户和审核数据?
任何帮助将不胜感激。
我的最终目标是检索某个位置的所有评论,但现在只是想把它作为前奏。
【问题讨论】: