문제

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.

도움이 되었습니까?

해결책

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:

https://developers.google.com/drive/examples/php

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top