Google Analytics API oauth wyjątek „invalid_grant” z kontem usługi. Ten sam kod na dwóch serwerach. Tylko jeden działa

Pytam o interfejs API Analytics przez aKonto usługi.

Napisałem kod na serwerze dev i działa bez problemów. Podczas uruchamiania tego samego kodu na serwerze produkcyjnym zgłasza to:

Google_AuthException: Błąd odświeżania tokenu OAuth2, komunikat: '{"error": "invalid_grant"}'

Próbowałem utworzyć inne konto usługi, a zachowanie jest takie samo.

Projekt oAuth IETF (http://tools.ietf.org/html/draft-ietf-oauth-v2-31) mówi o błędzie:

     invalid_grant
           The provided authorization grant (e.g. authorization
           code, resource owner credentials) or refresh token is
           invalid, expired, revoked, does not match the redirection
           URI used in the authorization request, or was issued to
           another client.

Oto kod, który napisałem:

$GA_CLIENT_ID = 'XX.apps.googleusercontent.com';
$GA_APP_EMAIL = '[email protected]';
$GA_APP_NAME = 'XX';
$GA_KEY_FILE = 'XX';

// create client object and set app name
$client = new Google_Client();
$client->setApplicationName($GA_APP_NAME); // name of your app

// set assertion credentials
$client->setAssertionCredentials(
        new Google_AssertionCredentials(
            $GA_APP_EMAIL, // email you added to GA
            array('https://www.googleapis.com/auth/analytics.readonly'),
            file_get_contents($GA_KEY_FILE)  // keyfile you downloaded
            ));

// other settings
$client->setClientId($GA_CLIENT_ID);           // from API console
$client->setAccessType('offline_access');  // this may be unnecessary?

// create service and get data
$service = new Google_AnalyticsService($client);
$result = $service->data_ga->get($ids, $startDate, $endDate, $metrics, $optParams);
return $result;

Próbowałem też rozwiązania sugerowanego tutaj (https://groups.google.com/forum/?fromgroups#!topic/gs-discussion/3y_2XVE2q7U%5B1-25%5D) przy użyciu authenticatedRequest () zamiast Google_AnalyticsService:

$req = new Google_HttpRequest($apiUrl);
$resp = $client::getIo()->authenticatedRequest($req);
$result = json_decode($resp->getResponseBody(), true);

Ta alternatywa działa również na serwerze dev, ale nie na serwerze produkcyjnym.

Nie mam pojęcia o tym. Czy ktoś widział to / naprawił?

Dzięki!

questionAnswers(4)

yourAnswerToTheQuestion