2012-06-11 77 views
1

我正在嘗試爲我的帳戶使用谷歌分析API。所以,我首先允許應用程序訪問離線刷新令牌。當我嘗試刷新令牌時購買「無效授權」錯誤。試圖刷新與PHP客戶端庫和手動捲曲。谷歌刷新令牌獲得無效授予錯誤

這是手動的捲曲度:

$oauth2token_url = "https://accounts.google.com/o/oauth2/token"; 
    $clienttoken_post = array(
    "client_id" => 'xxxxxxxx-d28qutrse5bvaf7n4a37qgs5ieijvp9n.apps.googleusercontent.com', 
    "client_secret" => 'xxxxxxxxxxxxx'); 

     $clienttoken_post["refresh_token"] = $refresh_token; 
     $clienttoken_post["grant_type"] = "refresh_token"; 

    $curl = curl_init($oauth2token_url); 

    curl_setopt($curl, CURLOPT_POST, true); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $clienttoken_post); 
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 

    $json_response = curl_exec($curl); 
    curl_close($curl); 

    $authObj = json_decode($json_response); 

    print_r($authObj); 


    exit(); 

刷新令牌我用simple.php例子得到了與以前的電話:

require_once '../../src/apiClient.php'; 
require_once '../../src/contrib/apiAnalyticsService.php'; 
session_start(); 

$client = new apiClient(); 
$client->setApplicationName("Google Analytics PHP Starter Application"); 

// Visit https://code.google.com/apis/console?api=analytics to generate your 
// client id, client secret, and to register your redirect uri. 
$client->setClientId('xxxxxxxxx-d28qutrse5bvaf7n4a37qgs5ieijvp9n.apps.googleusercontent.com'); 
$client->setClientSecret('xxxxxx'); 
$client->setRedirectUri('https://www.xxxxxxxxxx.org/oauth2callback/google-api-php-client/examples/analytics/simple.php'); 
$client->setDeveloperKey('xxxxxxx'); 



if (isset($_GET['logout'])) { 
    unset($_SESSION['token']); 
} 

if (isset($_GET['code'])) { 
    $client->authenticate(); 
    $_SESSION['token'] = $client->getAccessToken(); 
    header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); 
} 

if (isset($_SESSION['token'])) { 
// echo $_SESSION['token']; 
    $client->setAccessToken($_SESSION['token']); 
} 
echo $client->getAccessToken() 

回答

5

如果有人有興趣,我終於解決了這個問題後,幾小時:

我去了oauth操場:https://code.google.com/oauthplayground 在右邊,有一個設置按鈕。選中「使用您自己的OAuth憑據」。從那裏拿走了刷新標記,並且沒有問題。

1

如果別人運行到這個問題......

我們有一個問題,即同一職位要求不會開始工作,但工作以後。

對我們來說,它看起來像谷歌是非常挑剔的時間 - 嘗試減去5分鐘。