问题
We've been working on an application for about 2 months, and everything was going perfectly. we were using PHP SDK and offline mode in permissions for login But since some days ago after recent changes in Facebook api and removing offline mode we started facing the problem of "Uncaught OAuthException: An active access token must be used to query information about the current user."
The main problem is that it does happen after a while working in our app (about 10 mins) but at the same time when we check the validity of the token via this link we see that the token is still valid on the other hand the cookie does still exist and it doesn't expire but we get this error : "Uncaught OAuthException: An active access token must be used to query information about the current user"
I've already visited this link and I downloaded the latest version but it didn't help could anyone help us please where might be making mistake?
Thanks for responses, I think same as yacon it seems there's a bug when accessing facebook->api(/me) at the moment we are handling some parts of the app with javascript which is a real headache to use javascript sdk and PhP sdk alongside with each other
回答1:
You can solve this simply store accesstoken to session variable after getLoginUrl
$facebook->getLoginUrl(...)
then whenever you initialize facebook
$facebook = new Facebook(array( 'appId' => Yii::app()->params['facebook_appId'], 'secret' => Yii::app()->params['facebook_appSecret'], ));
get the accesstoken from session and set it using setAccessToken
$facebook->setAccessToken(Yii::app()->session['access_token']);
回答2:
I handle this situation in this way
1.i get the access token for 1 hour validity
2.extend the token to 60 days validity
3.save that token to session and use it for all project queries.
try{
$facebook_uid = $facebook->getUser();
$facebook->setExtendedAccessToken();
$accessToken = $facebook->getAccessToken();
$fbuser = $facebook->api('/me');
$session['api_me'] = $fbuser;
$session['tokenValue'] = $accessToken;
}catch (Exception $e) {
facebook_uid =null;
}
回答3:
I think there is a bug in the api. When I use $facebook->api('/'.$facebook_uid) instead of ->api('/me') it works.
来源:https://stackoverflow.com/questions/13777181/the-access-token-is-valid-but-we-get-oauthexception-an-active-access-token-erro