mardi 17 novembre 2015

google analytics custom plugin getting error invalid grant

$client = new Google_Client();
            $client->setAuthConfigFile(plugin_dir_url( __FILE__ ) . '/client_secrets.json');
            $client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
            $client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);
            $client->setIncludeGrantedScopes(true);
            $client->setAccessType('offline');
            $client->revokeToken();
            $auth_url = $client->createAuthUrl();

using a popup authentication with javascript and then

if (!isset($_SESSION['access_token'])) {
            //$client->authenticate($_GET['code']);
            $client->authenticate($this->options['authenication_code']);//authentication code saved as setting option

$google_token= json_decode($_SESSION['access_token']); //commenting this line and the line just below

          $client->refreshToken($google_token->refresh_token);

//this line works. I can retrieve the data with this after authentication, but when I am trying to get this in another session I am getting the error.I need to authenticate the plugin another time to get the data

            $_SESSION['access_token'] = $client->getAccessToken();
        }

I think there is some problem with refresh token, either I am not able to retrieve it or I am not able to reuse It .If any one has faced this situation please help me.

This is my 4th week on this but still unable to get things correctly.

I have gone through certain posts but no luck

1.Unable to refresh OAuth2 token in PHP, invalid grant

2.authenticate() accepts invalid tokens

3.Getting "invalid_grant" error on token refresh

4.Problem in refreshing access token

5.Why do I keep catching a Google_Auth_Exception for invalid_grant?

6.How to refresh token with Google API client?

and some more if I need to post more codes or anything else please let me know.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire