Choosing 'Not Now' when accepting app causes “com.facebook.sdk error2”

Using Facebook iOS SDK 3.1.

When choosing not to allow a ‘Connect’ to a Facebook app, I’m stuck with Facebook throwing “com.facebook.sdk error2.” errors at me, even after re-installing my app.

  • Facebook API dialog page showing error in second time and after that
  • Upload large videos to Facebook with iOS SDK
  • issue using FBSDK in swift iOS application
  • Link to Safari “Add to Home Screen” from inside app?
  • Ionic 2 Facebook Login - 'App Not Setup' & 'Not Logged in' & 'Given URL is not allowed' Errors
  • Facebook iOS SDK Poke
  • Steps to reproduce:

    1. Choose to connect with Facebook
    2. Select ‘Not Now’ in the UIAlertView that pops up

    => I can’t choose to connect again.

    The only way for the user to connect again is to remove her Facebook account from Settings and add it again.

    Is this a bug in the Facebook SDK or am I missing something?

    I’ve obviously followed the authorization tutorial and everything works just fine (auth, posting stuff) when choosing to connect.

    2 Solutions Collect From Internet About “Choosing 'Not Now' when accepting app causes “com.facebook.sdk error2””

    OK, so I figured out what goes on here. When declining authorization of the app, this is stored as a setting on your device’s Facebook account (Settings > Facebook).

    By going to Settings and re-enabling the app in question, you can try to connect again. Not very clear to users, but you can catch this error and show some kind of info to the user.

    This is how I implemented it (compared to Facebook’s default error handling):

    - (void)sessionStateChanged:(FBSession *)session
                          error:(NSError *)error {
    if (error) {
            NSString *errorTitle = NSLocalizedString(@"Error", @"Facebook connect");
            NSString *errorMessage = [error localizedDescription];
            if (error.code == FBErrorLoginFailedOrCancelled) {
                errorTitle = NSLocalizedString(@"Facebook Login Failed", @"Facebook Connect");
                errorMessage = NSLocalizedString(@"Make sure you've allowed My App to use Facebook in Settings > Facebook.", @"Facebook connect");
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:errorTitle
                                                      cancelButtonTitle:NSLocalizedString(@"OK", @"Facebook Connect")
            [alertView show];


    I had the same issue when I was trying to log in on Facebook using Facebook framework when an account is added in the setting but I fixed this by using the following code:

    as much as I know “com.facebook.sdk error2.” comes when there is an account is added in the iphone.


    @property (strong, nonatomic) FBSession *mysession;

    just add the method in the appdelegate.m

        if (!self.mysession.isOpen) {
            // create a fresh session object
            self.mysession = [[FBSession alloc] initWithPermissions:permissions];
            [self.mysession openWithCompletionHandler:^(FBSession *session,
                                                        FBSessionState stat,
                                                        NSError *error){
                [self sessionStateChanged:session
             NSLog(@"Session Staet is = %u",stat);
                switch (stat){
                    case FBSessionStateClosed:
                    case FBSessionStateOpen:{
                            NSString *strAccessToken1 = [mysession accessToken];
                            NSLog(@"AccessToken = %@",strAccessToken1);
                            NSString  *urlstring1 = [NSString stringWithFormat:@"",strAccessToken1];
                            NSURL *url1 = [NSURL URLWithString:[urlstring1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
                            NSString  *jsonRes = [NSString stringWithContentsOfURL:url1 encoding:NSUTF8StringEncoding error:nil];
                            NSDictionary *facebookData = [jsonRes JSONValue];
                            NSLog(@"FBSessionStateOpen = %@",facebookData);
                            NSString *strFBID = [[NSString alloc]initWithString:[NSString stringWithFormat:@"%@",[facebookData objectForKey:@"id"]]];
                            NSString *strName = [[NSString alloc]initWithString:[facebookData objectForKey:@"name"]];
                            NSLog(@"FBSessionStateOpen = %@",strName);
                            NSString *ProfileImageURL = [NSString stringWithFormat:@"",strFBID];
                            NSLog(@"Profile image URL is = %@",ProfileImageURL);
                            NSString *strImageURl = [[NSString alloc]initWithString:ProfileImageURL];
                            strAccessToken = [[NSString alloc]initWithString:strAccessToken1];
                            strAppUserName = [[NSString alloc]initWithString:strName];
                            strFacebookUsername = [[NSString alloc]initWithString:strName];
                            strAppUserProfileImage = [[NSString alloc]initWithString:strImageURl];
                            strFacebookUserId = [[NSString alloc]initWithString:strFBID];

    this in my action method

            [appDelegate openSessionWithAllowLoginUI:YES];