I am trying to implement an example of using a google services account. What I want to do is very basic - create a connection, set the service provider, pull back some data. For some reason however, when I follow the example provided (https://github.com/google/google-api-php-client/blob/master/examples/service-account.php) it fails with the following error:
Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }'
I have scoured google trying to figure this out, and have found a few things here on StackOverflow, but none of them have solved my issue. Im hoping someone out there can help me. Here is the code I am working with:
//initialize a new Google client
$client = new Google_Client();
$client->setApplicationName("books-provider-example");
$this->service = new Google_Service_Books($client);
//do we already have a service token?
if (isset($this->service_token)) {
$client->setAccessToken($this->service_token);
}
//setup the credentials
$credentials = new Google_Auth_AssertionCredentials(
$GLOBALS['GSERVICES']['clientemail'],
$GLOBALS['GSERVICES']['scopes'],
file_get_contents($GLOBALS['GSERVICES']['keypath']),
'notasecret'
);
$client->setAssertionCredentials($credentials);
//refresh the auth token if its expired
if ($client->getAuth()->isAccessTokenExpired())
$client->getAuth()->refreshTokenWithAssertion();
//set the service token
$this->service_token = $client->getAccessToken();
Any help in getting this to work is greatly appreciated!