Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(com.facebook.sdk.login error 304.) Error with FBSDK 4.2

Tags:

I am trying to implement login with Facebook functionality, But I am getting following error in return.

Login Failed with error: The operation couldn’t be completed. (com.facebook.sdk.login error 304.)

Here is my Code

    - (void)loginWithFacebook {         NSString *const read_actions = @"email";          [[[FBSDKLoginManager alloc] init]          logInWithReadPermissions:@[read_actions] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)          {              if (error) {                  NSLog(@"Login Failed with error: %@", error.localizedDescription);              }              else if (result.isCancelled)              {                  NSLog(@"Login Failed due to Cancel");              }              else              {                  if ([result.grantedPermissions containsObject:read_actions]) {                      NSLog(@"Permission granted");                   }              }          }];     } 
like image 924
Hassan Aftab Avatar asked Jul 01 '15 08:07

Hassan Aftab


2 Answers

This may because of previous login token not cleared.So before login just logout.

NSString *const read_actions = @"email"; FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init]; [loginManager logOut]; [loginManager logInWithReadPermissions:@[read_actions]                                handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {                                    if (error) {                                        NSLog(@"Login Failed with error: %@", error.localizedDescription);                                    }                                    else if (result.isCancelled) {                                        NSLog(@"Login Failed due to Cancel");                                    } else {                                        if ([result.grantedPermissions containsObject:read_actions]) {                                            NSLog(@"Permission granted");                                         }                                    }                                }]; 
like image 200
Minal Soni Avatar answered Oct 21 '22 07:10

Minal Soni


Swift 4 update :

Everytime you perform something like this

    FBSDKLoginManager().login(withReadPermission: ["email"], from: self) { (result, error) in  // Check for error and then login } 
    //insert this code before the **Login code:**      FBSDKLoginManager().logOut() 

and it should work fine :)

like image 22
Sanket Ray Avatar answered Oct 21 '22 07:10

Sanket Ray