【问题标题】:Can't get any account info, or review info无法获取任何帐户信息或评论信息
【发布时间】:2019-11-18 23:21:17
【问题描述】:

我已经尝试了几个小时来解决这个问题,但我完全陷入困境。

我的业务 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 检索帐户和审核数据?

任何帮助将不胜感激。

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

【问题讨论】:

    标签: google-my-business-api


    【解决方案1】:

    回答我自己的问题 - 我认为主要问题是事实证明 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=

    【讨论】:

    • 我已经被困在这个问题上很久了,仅仅试图找到 accountID(或上面提到的 account_number)已被证明是一项不可能完成的任务。我在哪里可以买到这个?
    • 这是我为这项工作创建的 Drupal 模块,请查看 .module 文件 -> github.com/joehuggans/Drupal-7-Google-MyBusiness-API 对不起,这是很久以前的事了,我不记得我做了什么在这里。
    猜你喜欢
    • 1970-01-01
    • 2013-04-29
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多