4

几天来我一直在调试这个问题,但我想不出任何其他方法来解决这个问题。

错误

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 是我的 colo 公司的时间服务器)

我已经在 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', 'XXXXXX510496@developer.gserviceaccount.com');
    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>";

 ?>

我已经完全没有想法了,所以任何帮助将不胜感激!

4

1 回答 1

0

我刚刚发布了一份可能会帮助您摆脱困境的文件:

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

于 2013-01-05T19:32:05.000 回答