ios facebook sdk 4.0 login error code 304 ios facebook sdk 4.0 login error code 304 ios ios

ios facebook sdk 4.0 login error code 304


I had a similar problem.

After initialising FBSDKLoginManager I added a line to flush out the data and the (Facebook)Token:

FBSDKLoginManager *loginmanager= [[FBSDKLoginManager alloc]init];    [loginmanager logOut];

Hope this helps.


Thus, exactly as the OP asks, "am I missing something"?

Yes, the following standard example code which is seen everywhere, is simply wrong:

-(IBAction)facebookLoginClick:(id)sender{FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];---- ONE MAGIC LINE OF CODE IS MISSING HERE ----[login logInWithReadPermissions:@[@"email"]   handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)    {    if (error) {...}    else if (result.isCancelled) {...}    else { // (NB for multiple permissions, check every one)       if ([result.grantedPermissions containsObject:@"email"])          { NSLog(@"%@",result.token); }       }}];}

you must do this:

-(IBAction)facebookLoginClick:(id)sender{FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];[login logOut];   //ESSENTIAL LINE OF CODE[login logInWithReadPermissions:@[@"email"]   handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)    {    if (error) {...}    else if (result.isCancelled) {...}    else { // (NB for multiple permissions, check every one)       if ([result.grantedPermissions containsObject:@"email"])          { NSLog(@"%@",result.token); }       }}];}

Otherwise, very simply, the app will not work if the user happens to change FB accounts on the device. (Unless they happen to for some reason re-install the app!)

Once again - the popular sample code above simply does not work (the app goes in to an endless loop) if a user happens to change FB accounts. The logOut call must be made.


This happened to me when I changed the Facebook AppID (in the Info.plist file) switching form a test Facebook app to a production Facebook app. If your app sends the Facebook token to a server that generate a JWT for for instance, Facebook SDK still persists the fbToken (FBSDKAccessToken.currentAccessToken()) persisted unless it's told to remove it.That may also happen in production when a user logs out of the app, a log out API request will log the user out and reset your JWT. But even before sending the log out API request, the client will need to tell the FBSDKLoginManager instance to log out.

if let currentAccessToken = FBSDKAccessToken.currentAccessToken() where currentAccessToken.appID != FBSDKSettings.appID()    {        loginManager.logOut()    }


I had this, it occurred when changing the FB app details in Xcode while an iOS app was running. You need to delete the app from the device and then republish with the new FB app setup. Just recompiling is not enough to clear the old FB settings