(com.facebook.sdk.login error 304.) Error with FBSDK 4.2
18,362
Solution 1
It seems I was doing
[FBSDKAccessToken refreshCurrentAccessToken:^(FBSDKGraphRequestConnection *connection, id result, NSError *error){}
in a background thread during login operation. I removed that and It worked perfectly fine.
Solution 2
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");
}
}
}];
Solution 3
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 :)
Solution 4
Log out the fblogin manager on action which you are performing login just before the login api like:-
fbLoginManager.logOut()
fbLoginManager.logIn(withReadPermissions: ["public_profile","email"], from: self) { (result, error) -> Void in
//Your code here
}
Solution 5
Swift 5 update :
Just refresh your accessToken or logout first.
func loginButtonClicked() {
let loginManager = LoginManager()
loginManager.logOut()
loginManager.logIn(permissions: [.email], viewController: nil) { (loginResult) in
switch loginResult {
case .success(let grantedPermissions, _, let token):
self.returnUserData()
print("Success",token,grantedPermissions)
break
case .cancelled:
print("Cancel")
break
case .failed(let error):
print(error.localizedDescription)
break
}
}
}
Author by
Hassan Aftab
Software Engineer with 7 year experience. Working in iOS
Updated on June 06, 2022Comments
-
Hassan Aftab almost 2 years
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"); } } }]; }