Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Google auth api刚刚返回“意外错误”_Php_Google Analytics_Google Analytics Api - Fatal编程技术网

Php Google auth api刚刚返回“意外错误”

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

上面的php代码给出了以下内容:

test1/test2/test3/发生意外错误。请联系 站长

这意味着代码运行时会发生错误:

        $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());
    }
}