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;
}
}