Getting the famous invalid_grant on my live web site

111 views
Skip to first unread message

Juan Diego Calle

unread,
Oct 29, 2013, 7:26:08 PM10/29/13
to google-api...@googlegroups.com
Hi,

I developed my google fusion app for joomla in my laptop (actually i just upgraded my old fusion table app to the new api), and everything works on my laptop.  I uploaded it to my server and I cant get a token, I get

400 - An error has occurred.

Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }'


I created another client key for my server, changed everything to that account an nothing works on my server.  Only on my laptop.  I thought that maybe the key was wrong but changed my laptop, and it works


Here is my code

/* old key, i use this one my laptop

const CLIENT_ID = '620XXXXXXXXXXXXXXXXXXXXXXXXXpu.apps.googleusercontent.com';
const SERVICE_ACCOUNT_NAME = ''620XXXXXXXXXXXX...@developer.gserviceaccount.com';
const KEY_FILE = '/home/jdc/workspace/1ffXXXXXXXXXXXXXXXXXXXX-privatekey.p12';
*/

// New key, i tried first on my webserver, then i tried on my laptop, it works only in my laptop

const CLIENT_ID = '62YYYYYYYYYYYYYYYYYYYYYYYYYYYpa.apps.googleusercontent.com';
const SERVICE_ACCOUNT_NAME = '62YYYYYYYYYYYYY...@developer.gserviceaccount.com';
const KEY_FILE = '/home/jdc18/4bYYYYYYYYYYYYYYYYYYYYY-privatekey.p12';


class ClientLogin {
    public static function getAuthToken($username, $password) {
        $client = new Google_Client();
        $client->setApplicationName("API Project");
        $client->setClientId(CLIENT_ID);

        // Set your cached access token. Remember to replace $_SESSION with a
        // real database or memcached.
        if (isset($_SESSION['token'])) {
            $client->setAccessToken($_SESSION['token']);
        }

        $key = file_get_contents(KEY_FILE);

        $client->setAssertionCredentials(new Google_AssertionCredentials(
                SERVICE_ACCOUNT_NAME,
                array('https://www.googleapis.com/auth/fusiontables'),
                $key)
        );
        //var_dump($_SESSION);
        //$client->authenticate();

        if ($client->getAuth()->isAccessTokenExpired()) {
            //var_dump($client->getAuth());
            $client->getAuth()->refreshTokenWithAssertion();
        }

        if ($client->getAccessToken()) {
            $_SESSION['token'] = $client->getAccessToken();
        }


        $token = $_SESSION['token'];

        var_dump($token);
           
        return $token;
    }
}


Reply all
Reply to author
Forward
0 new messages