Access tokens expire after one hour. Perhaps you are trying to reuse an access token that has expired?
Check the DrEdit application for a complete PHP sample showing how to properly store credentials in a db and restore them when needed:
Question
I'm trying to do a simple list (in php) of all the files that a user have in his drive. I wanna save the access token, user id and email in bd and to get the user id and email I wrote this code:
(..)
$api=new Google_Client();
$api->setAccessToken($accessToken);
$api->setUseObjects(true);
$userInfoService = new Google_Oauth2Service($api);
$userinfo=$userInfoService->userinfo->get();
(..)
In the last line of this sample I get this error:
Error calling GET https://www.googleapis.com/oauth2/v2/userinfo: (401) Invalid Credentials
but I print the accessToken that I send and it's correct.
Solution
Access tokens expire after one hour. Perhaps you are trying to reuse an access token that has expired?
Check the DrEdit application for a complete PHP sample showing how to properly store credentials in a db and restore them when needed: