My goal is to make the simplest query on Google Fusion Tables
on behalf of my web app users. For that, I created a service account on google console. Here is the code:
// Creating a google client
$client = new \Google_Client();
// setting the service acount credentials
$serviceAccountName = 'XXXXX.apps.googleusercontent.com';
$scopes= array(
'https://www.googleapis.com/auth/fusiontables',
'https://www.googleapis.com/auth/fusiontables.readonly',
);
$privateKey=file_get_contents('/path/to/privatekey.p12');
$privateKeyPassword='notasecret'; // the default one when generated in the console
$credential = new \Google_Auth_AssertionCredentials($serviceAccountName,
$scopes, $privateKey, $privateKeyPassword);
// setting assertion credentials
$client->setAssertionCredentials($credential);
$service = new \Google_Service_Fusiontables($client);
$sql = 'select name from XXXXXXXX';
$result = $service->query->sql($sql);
After running this code, I got this error:
Error refreshing the OAuth2 token, message: '{
"error" : "invalid_grant"
}'
I googled that for days and most of answers are talking about refreshing the token. I made this refresh but still the same errors!
Any idea for solving this problem? Thanks