google-api-php-client icon indicating copy to clipboard operation
google-api-php-client copied to clipboard

refreshTokenWithAssertion Failing reauthentication

Open jmckay56 opened this issue 10 years ago • 2 comments

I am running a script to patch 2000 business using Google My Business At record 900 i get "code": 401, "message": "Request had invalid authentication credentials.",

Before each curl call I am checking the token

if ($client->isAccessTokenExpired()) { $oauth2Token = $client->refreshTokenWithAssertion()['access_token']; }

Are there any timeout issues here? Is this the correct implementation for "google/apiclient": "2.0.0-RC7"

jmckay56 avatar May 05 '16 00:05 jmckay56

What you are doing looks correct. It does seem like refreshTokenWithAssertion is not successfully fetching the token.

I would debug what is being returned first, and see if that sheds any light on the issue. If a JSON error is the response from the HTTP server, then that error will be returned from refreshTokenWithAssertion:

if ($client->isAccessTokenExpired()) {
    $result = $client->refreshTokenWithAssertion();
    if (!isset($result['access_token'])) {
        throw new \Exception('unexpected response: ' . json_encode($result));
    }
    $oauth2Token = $result['access_token'];
}

If that doesn't work, you should be able to use a web proxy like Charles to debug the HTTP request going across the wire:

$client = new Google_Client;
$http = new GuzzleHttp\Client([
    'proxy' => 'localhost:8888', // this is where charles is running
    'verify' => false,
]);
$client->setHttpClient($http);

bshaffer avatar May 05 '16 20:05 bshaffer

This issue has been closed due a lack of response. Please reopen with more information if the problem is still occurring.

bshaffer avatar May 17 '16 21:05 bshaffer