无法获取任何帐户信息或评价信息



我已经尝试了几个小时来解决这个问题,但我完全被卡住了。

我已经获得了My Business APi的批准,我创建了一个服务帐户并下载了json文件进行身份验证。

我使用的是谷歌api php客户端和谷歌api我的业务php客户端,后者提供了"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检索帐户和查看数据?

如有任何帮助,我们将不胜感激。

我的最终目标是检索一个地点的所有评论,但现在只是想把它作为前奏。

回答我自己的问题-我认为主要问题是my Business api不支持服务帐户,您需要使用oauth2。

结果发现,V3也贬值了,所以我为MyBusiness API使用的库是无用的,另一个库用于更新访问令牌。

对于评论,我只是使用Curl并简单地用构建URL?访问令牌=其末尾的值。

例如列出所有评论

https://mybusiness.googleapis.com/v4/accounts/[账号]/地点/[地点id]/评论?access_token=

最新更新