Error refreshing the OAuth2 token { “error” : “invalid_grant” }
There is two possibles cause for this error that I know:
(i) You have the wrong email in your
$client_id = '1303030303-wrongiddontuse7t9kdtai3l44jofnejr04.apps.googleusercontent.com'; //Client ID $service_account_name = '1303030303-wrongiddontuse7t9kdtai3l44jofnejr04@developer.gserviceaccount.com'; //Email Address $key_file_location = 'API Project-1234.p12'; //key.p12
Often people enter their own email address, but it must look like this weird cryptic string above. You can get your own ID on the developer's console page (assuming you paid and have an google for business account) :
https://console.developers.google.com/project/<yourProjectID>/apiui/credential
(2) You don't have enabled the specific scope which you are trying to access. For example in the examples/service-account.php sample provided, it tries to access the "Books API". In the screenshot below you see the three APIs enabled, you must have the one in your credential object :
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array('https://www.googleapis.com/auth/books'),
$key );

Recent Comments