Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook iOS SDK 3.1.1 "closeAndClearTokenInformation" method no working

I just upgraded from Facebook iOS SDK 3.0.X to 3.1.1, and rewrote some code...

As per Facebook documentation for the logout workflow (https://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/authenticate/#step3), I'm calling the closeAndClearTokenInformation method of the FBSession.activeSession object.

This seems to have no effect on the Facebook session state, because checking it right after the call still returns an open session.

As it stands, once my application logs in with Facebook, it doesn't logout.

[UPDATE 1]

As requested, here's the code I use to check the session state:

if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded && FBSession.activeSession.isOpen)
 //logged in
else
 //not logged in

[UPDATE 2]

Changed my logic a bit... Altered my original code to:

if (FBSession.activeSession.isOpen)
 //logged in
else
 //not logged in

Because FBSession.activeSession.state was returning FBSessionStateOpen, not FBSessionStateCreatedTokenLoaded.

like image 904
Spencer Müller Diniz Avatar asked Oct 15 '12 13:10

Spencer Müller Diniz


2 Answers

Maybe this will help. https://developers.facebook.com/bugs/497294866962479?browse=search_507cb8ebc4f025673237228

I call all these methods together to make sure it is really logout. Crazy bugs.

[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
[FBSession setActiveSession:nil];
like image 180
user725840 Avatar answered Nov 14 '22 15:11

user725840


I know this may be late but on Android (3.0 SDK) the Session.getActiveSession() may return null if you're not in the same Context where you created it (or if the app was closed and the session didn't get somehow restored). It happens and it's handled by the SDK so there isn't much you can really do.

In those cases, calling closeAndClearTokenInformation() doesn't do much (if you take a look at the source code you will understand why). The solution to me was something along these lines (in Java):

Session session = Session.getActiveSession();
if (session != null) {
   Session.getActiveSession().closeAndClearTokenInformation();
   Session.getActiveSession().close();
   Session.setActiveSession(null);
} else {
   // construct a new session (there are different ways to do this, this is how I do it because I need to pass the FACEBOOK_API_KEY programmatically).
   session = new Session.Builder(MyApp.getInstance()).setApplicationId(Constants.FACEBOOK_API_KEY).build();
   if (session != null) {//to be safe
     //beware with the case of Session vs sesssion.
     Session.setActiveSession(session); 
     session.closeAndClearTokenInformation();
     session.close();
     Session.setActiveSession(null);
   }
}

This effectively leaves my session as:

{Session state:CREATED, token:{AccessToken token: permissions:[]}, appId:xxxxx}

Remember that created is not the same as Closed (or Open). From that state you can re-open the session without problems.

Hope this helps.

like image 27
Martin Marconcini Avatar answered Nov 14 '22 16:11

Martin Marconcini