2013-01-02 38 views
3

我一直在調試這個問題幾天,但我想不出其他任何東西來嘗試解決這個問題。當時間同步時使用Google服務帳戶的invalid_grant錯誤

錯誤

Fatal error: Uncaught exception 'Google_AuthException' with message 'Error refreshing the OAuth2 token, message: '{ 
    "error" : "invalid_grant" 
}'' in /html/cms/php/google-api-php-client/src/auth/Google_OAuth2.php:279 
Stack trace: 
#0 /html/cms/php/google-api-php-client/src/auth/Google_OAuth2.php(256): Google_OAuth2->refreshTokenRequest(Array) 
#1 /html/cms/php/google-api-php-client/src/auth/Google_OAuth2.php(209): Google_OAuth2->refreshTokenWithAssertion() 
#2 /html/cms/php/google-api-php-client/src/service/Google_ServiceResource.php(166): Google_OAuth2->sign(Object(Google_HttpRequest)) 
#3 /html/cms/php/google-api-php-client/src/contrib/Google_CalendarService.php(154): Google_ServiceResource->__call('list', Array) 
#4 /html/cms/php/google_calendar_sync.php(41): Google_CalendarListServiceResource->listCalendarList() 
#5 {main} 
    thrown in /html/cms/php/google-api-php-client/src/auth/Google_OAuth2.php on line 279 

我的服務器的時鐘是同步: 1月2日13點35分36秒用ntpdate [1214]:調整時間服務器62.212.76.57偏移0.003544秒 (62.212 .76.57是我的科洛公司的時間服務器)

我已經在Google API控制檯中檢查了我的服務帳戶開發人員憑據的三重檢查(我有一個截圖,但由於我的帳戶太新,所以無法使用它):/ 。我也成功訂閱了日曆服務(也無法使用我製作的截圖)。

我的代碼

<?php 

    require_once(dirname(__FILE__) . '/google-api-php-client/src/Google_Client.php'); 
    require_once(dirname(__FILE__) . '/google-api-php-client/src/contrib/Google_CalendarService.php'); 

    session_start(); 

    define('CLIENT_ID', 'XXXXXX510496.apps.googleusercontent.com'); 
    define('SERVICE_ACCOUNT_NAME', '[email protected]'); 
    define('CALENDAR_ID', 'XXXXXXXXXXXXXXXXX'); 
    define('KEY_FILE', dirname(__FILE__) . '/private/XXXXXXXXXXXXXXXXXXXX881a845ed4e4d2d58eb1-privatekey.p12'); 

    $client = new Google_Client(); 

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

    $key = file_get_contents(KEY_FILE); 
    $client->setClientId(CLIENT_ID); 
    $client->setAssertionCredentials(new Google_AssertionCredentials(
     SERVICE_ACCOUNT_NAME, 
     'https://www.google.com/calendar/feeds/' . CALENDAR_ID . '/private/full/', 
     $key) 
    ); 

    $service = new Google_CalendarService($client); 

    $calendarList = $service->calendarList->listCalendarList(); 
    echo "<h1>Calendar List</h1><pre>" . print_r($calendarList, true) . "</pre>"; 

?> 

我已經完全用完的想法,所以任何幫助將非常感激!

回答

0

我剛剛發佈了一個文件,可以幫助你擺脫這種困境:

http://www.tqis.com/eloquency/googlecalendar.htm

+0

恐怕你的例子似乎沒有使用服務帳戶。我已經成功驗證爲「網絡應用程序」,但我仍然堅持這個問題。任何進一步的援助將非常感激。 –

相關問題