Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FBSDKLoginManager fails with error code - 308

We are using FBSDKLoginManager with our own UI for login to facebook. However sometimes the login fails with the error code 308.

As per docs the reason is - FBSDKLoginBadChallengeString, I have searched all over the internet to find out the reason for this but have had no luck.

Any explanation as to why this error occurs and how to resolve it?

like image 789
Adam Huie Avatar asked Jun 18 '15 18:06

Adam Huie


2 Answers

This is how I reproduced and solved the com.facebook.sdk.login error 308.

User A logs to Facebook, then logs into my app, finally logs out of my app using the popular:

func logOutFromFacebook(){

   if (FBSDKAccessToken.currentAccessToken() != nil){

           let loginManager = FBSDKLoginManager()
           loginManager.logOut()
    }
}

Now User B logs into Facebook, logs into my app and com.facebook.sdk.login error 308 shows up.

If I reinstall the app the new user can login without problems but certainly I don't want people reinstalling the app every time there is an account switch.

The solution that has solved this problem was to use FBSDKAccessToken.setCurrentAccessToken(nil) as below:

func logOutFromFacebook(){

   if (FBSDKAccessToken.currentAccessToken() != nil){

     FBSDKAccessToken.setCurrentAccessToken(nil)

        By itself I had no use for it, maybe you might want to uncomment.
        //   let loginManager = FBSDKLoginManager()
        //   loginManager.logOut()

    }
}

Hope it helps someone!

like image 155
Carlitos Avatar answered Nov 14 '22 02:11

Carlitos


The reason I had this error was that my login and logout code used two different instances of the FBSDKLoginManager.

see my answer here https://stackoverflow.com/a/32659830/4068264

(I do not have the reputation for comments so apologies to the community if this response does not fall in the category of "Answer")

like image 3
loudmouth Avatar answered Nov 14 '22 02:11

loudmouth