Search code examples
objective-cfacebookios6facebook-ios-sdk

Facebook login failing on iOS 6


When I try to login using Facebook iOS SDK I get the error The operation couldn't be completed (com.facebook.sdk error 2).

The state of the session is: FBSessionStateClosedLoginFailed.

THis is my code now:

-(void) callFBService{

    NSArray *permissions = [[NSArray alloc] initWithObjects:@"email, publish_stream, user_likes, friends_likes", nil];
    [FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES
                              completionHandler:^(FBSession *fbsession,
                                                  FBSessionState status,
                                                  NSError *error) {
          if(error)
          {
              NSLog(@"Session error");
              [self fbResync];
              [NSThread sleepForTimeInterval:0.5];   //half a second
              [FBSession openActiveSessionWithReadPermissions:permissions
                                                 allowLoginUI:YES
                                            completionHandler:^(FBSession *fbsession, FBSessionState status, NSError *error) {
                                                [self sessionStateChanged:fbsession state:status error:error];
                                            }];

          }
          else
              [self sessionStateChanged:fbsession state:status error:error];

     }];
}

I have tried everything in the following posts:

The operation couldn’t be completed. (com.facebook.sdk error 2.) ios6 Facebook Registration : The operation couldn't be completed (com.facebook.sdk error 2) Facebook SDK 3.1 iOS: Handle login if user remove app from Facebook Settings

Any ideas??? Please!


Solution

  • You're passing publish_stream in with read permissions, but publish_stream is a write permission. It's also deprecated (use publish_actions instead). Try removing that permission. You'll need to ask for that permission separately, after you get your user logged in with read permissions. See the SDK docs: https://developers.facebook.com/docs/technical-guides/iossdk/login/#read

    In addition, a few things to check: Make sure your app on Facebook.com is configured correctly, including the bundle ID. Make sure the user you're attempting to log in has rights to the app (if the app is in sandbox mode, make sure the user is added as a tester and has approved this).