Google API错误 - "找不到OAuth客户端"

时间:2017-03-02 15:47:41

标签: php oauth google-api

我试图从php获取谷歌分析统计数据但没有成功。代码正在跟随,当我尝试刷新令牌

时错误发生
  

致命错误:未捕获Google_Auth_Exception:刷新错误   OAuth2令牌,消息:' {"错误" :" invalid_client",   " ERROR_DESCRIPTION" :"找不到OAuth客户端。" }'

$service_account_email = $this->settings->service_account_email;
$key_file_location = LOCALPATH.'plugins/google-api-php-client/client_secrets.p12';

$client = new Google_Client();
$client->setApplicationName("GetStats");

$client->setAccessType('offline');
$analytics = new Google_Service_Analytics($client);

$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
  $service_account_email,
  array(Google_Service_Analytics::ANALYTICS_READONLY),
  $key
);

$client->setAssertionCredentials($cred);

if($client->getAuth()->isAccessTokenExpired()) {
   $client->getAuth()->refreshTokenWithAssertion($cred);
}

return $analytics;

我认为问题出在google api控制台上,但我无法理解。

PS:如果你有一个更简单的选择来获取谷歌统计数据(使用php或javascript)我很乐意尝试它

0 个答案:

没有答案