0

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

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

我正在使用google-api-php-clientgoogle-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 检索帐户和审核数据?

任何帮助,将不胜感激。

我的最终目标是检索某个位置的所有评论,但现在只是试图让它作为前奏。

4

1 回答 1

0

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

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

对于评论,我只是使用 Curl 并简单地构建带有 ?access-token= 值的 URL。

例如列出所有评论

https://mybusiness.googleapis.com/v4/accounts/[acc-number]/locations/[location-id]/reviews?access_token=

于 2019-11-17T21:53:05.130 回答