doujing6053 2015-05-20 11:36
浏览 90

谷歌auth api只是返回'意外错误'

        $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/';
        }

The above php code spits out the following:

test1/test2/test3/An unexpected error has occurred. Please contact the webmaster.

This means that the error is happening when the code runs:

$client->getAuth()->refreshTokenWithAssertion($cred); 

I have checked and triple checked the serviceaccount.com email as well as the p12 key.. but i get nothing other than, unexpected error.

Has anyone else hit this wall before? I cannot see what is wrong with the code.

Following the post: refreshTokenWithAssertion Permission Denied

I altered the above code where it was failing to run a try catch, but the try does not fail!:

if($client->getAuth()->isAccessTokenExpired()) {
    try {
        $client->getAuth()->refreshTokenWithAssertion($cred);
    } catch (Exception $e) {
        echo 'Failed:';
        print_r($e->getMessage());
    }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测