Php Google auth api刚刚返回“意外错误”
上面的php代码给出了以下内容: test1/test2/test3/发生意外错误。请联系 站长 这意味着代码运行时会发生错误:Php Google auth api刚刚返回“意外错误”,php,google-analytics,google-analytics-api,Php,Google Analytics,Google Analytics Api,上面的php代码给出了以下内容: test1/test2/test3/发生意外错误。请联系 站长 这意味着代码运行时会发生错误: $client = new \Google_Client(); $client->setApplicationName('AnalyticsAPI'); $cred = new \Google_Auth_AssertionCredentials( '1010008554258-XXXX@de
$client = new \Google_Client();
$client->setApplicationName('AnalyticsAPI');
$cred = new \Google_Auth_AssertionCredentials(
'1010008554258-XXXX@developer.gserviceaccount.com',
array('https://www.googleapis.com/auth/analytics.readonly'),
\file_get_contents( __DIR__ . '/../google-keys/AnalyticsAPI-XXX.p12' )
);
echo 'test1/';
$client->setAssertionCredentials($cred);
echo 'test2';
if($client->getAuth()->isAccessTokenExpired()) {
echo 'test3/';
$client->getAuth()->refreshTokenWithAssertion($cred);
echo 'test4/';
}
我已经检查并三次检查了serviceaccount.com电子邮件以及p12密钥。。但我得到的只是一个意外的错误
以前有人撞过这堵墙吗?我看不出代码有什么问题
以下职位:
我修改了上面的代码,其中无法运行try-catch,但try没有失败!:
$client->getAuth()->refreshTokenWithAssertion($cred);
if($client->getAuth()->isAccessTokenExpired()) {
try {
$client->getAuth()->refreshTokenWithAssertion($cred);
} catch (Exception $e) {
echo 'Failed:';
print_r($e->getMessage());
}
}