简体   繁体   中英

OAuthException: An active access token must be used to query information about the current user

I've this error, but not always . (I use PHP SDK, latest version). If I'm logged into facebook and i try to register and login, then the app say it's ok! Also if i'm not logged into facebook, the app redirect me to login url, and here it's all ok.

But sometimes the app say this exception: OAuthException: An active access token must be used to query information about the current user. and the script redirect the user to loginUrl with a loop-redirect (because the access token isn't valid and user need always of loginUrl)

In the web some say that Facebook create a duplicate of Access Token and then access token of php sdk don't is = facebook.

For fix, the user must deletes cookies, how I can fix this?

Thanks a lot for reply , if code is need reply and I'll post it, have a good day! :)

Try to destroy the Facebook session, then redirect the user to login URI if you receive this error, this way you will get a fresh access token.

Notice: Access token expire after a very short, you can get a long living access token. The latest PHP SDK contains a public function called : setExtendedAccessToken()

you can call this function to automatically exchange the 2-3 hours living access token for a 60 days access token

Eg:

try {
      $user = $this->facebooknew->api('/me');
      $this->facebooknew->setExtendedAccessToken();
      $access_token = $this->facebooknew->getAccessToken();
}
catch(FacebookApiException $e){
      $this->facebooknew->destroySession();
      header('Location: ' . $this->facebooknew->getLoginUrl($params));
        //echo $e;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM