-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fatal error: Uncaught exception 'Google\Spreadsheet\UnauthorizedException' with message 'Access token is invalid' or Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error fetching OAuth2 access token, message: 'invalid_grant: i'' #43
Comments
There seems to be something wrong with the access token. Can you try and generate one using the following code and let me know if you still have an issue. https://github.com/asimlqt/php-google-oauth Note: The access token is only valid for one hour. |
@nekromoff I ran into the same problem, the issue is the Google api saves the access token as encoded json. I fixed it with:
|
I have the same issue, access token generated with official PHP API from Google is not working with this library Fatal error: Uncaught exception 'Google\Spreadsheet\UnauthorizedException' with message 'Access token is invalid' in /site/vendor/asimlqt/php-google-spreadsheet-client/src/Google/Spreadsheet/DefaultServiceRequest.php:250 Stack trace: #0 /site/vendor/asimlqt/php-google-spreadsheet-client/src/Google/Spreadsheet/DefaultServiceRequest.php(132): Google\Spreadsheet\DefaultServiceRequest->execute(Resource id #35) #1 /site/vendor/asimlqt/php-google-spreadsheet-client/src/Google/Spreadsheet/SpreadsheetService.php(38): Google\Spreadsheet\DefaultServiceRequest->get('feeds/spreadshe...') #2 /site/index.php(51): Google\Spreadsheet\SpreadsheetService->getSpreadsheets() #3 {main} Access token seems to be valid, because I can access my drive using official Google API, |
this works for me (using .p12 key):
|
|
I have this problem, I always get this:
{"access_token":"ya29.3AAc-8mXbyHSaOFS_TJJX4dkrvH92eY956HV5ZyR1mR6gTnQnr-jPzZkDEa0rJl9pOaR4lJ3DdGJuQ","token_type":"Bearer","expires_in":3600,"created":1418520786}
Fatal error: Uncaught exception 'Google\Spreadsheet\UnauthorizedException' with message 'Access token is invalid' in /whatever/vendor/asimlqt/php-google-spreadsheet-client/src/Google/Spreadsheet/DefaultServiceRequest.php:240 Stack trace: #0 /whatever/vendor/asimlqt/php-google-spreadsheet-client/src/Google/Spreadsheet/DefaultServiceRequest.php(131): Google\Spreadsheet\DefaultServiceRequest->execute(Resource id #46) #1 /whatever/vendor/asimlqt/php-google-spreadsheet-client/src/Google/Spreadsheet/SpreadsheetService.php(38): Google\Spreadsheet\DefaultServiceRequest->get('feeds/spreadshe...') #2 /whatever/sample.php(27): Google\Spreadsheet\SpreadsheetService->getSpreadsheets() #3 {main} thrown in /whatever/vendor/asimlqt/php-google-spreadsheet-client/src/Google/Spreadsheet/DefaultServiceRequest.php on line 240
scopes:
$client->setScopes(array('https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive','https://docs.google.com/feeds/'));
spreadsheet access code:
$serviceRequest = new Google\Spreadsheet\DefaultServiceRequest($token['access_token']);
Google\Spreadsheet\ServiceRequestFactory::setInstance($serviceRequest);
$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheets();
sometimes i get this instead:
Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error fetching OAuth2 access token, message: 'invalid_grant: i'' in /whatever/vendor/google/apiclient/src/Google/Auth/OAuth2.php:127 Stack trace: #0 /whatever/vendor/google/apiclient/src/Google/Client.php(130): Google_Auth_OAuth2->authenticate('4/gGfFncBJOs5id...') #1 /whatever/sample.php(19): Google_Client->authenticate('4/gGfFncBJOs5id...') #2 {main} thrown in /whatever/vendor/google/apiclient/src/Google/Auth/OAuth2.php on line 127
The text was updated successfully, but these errors were encountered: