Facebook Registration : The operation couldn't be completed (com.facebook.sdk error 2)

纵然是瞬间 提交于 2019-11-28 00:22:51

I think this will fix your issue:

  1. Go to you Facebook app in your Facebook account.
  2. Click edit your app.
  3. Go to Basic info tab.
  4. Sandbox Mode: check this as Disable
  5. Save the setting.

This will work for you.

First of all make sure about your Bundle Id should be correct.

And change your setting like it

Change sandbox setting disabled.

Also change your P-list setting like it

It will work fine. If you will face this problem again please let me know.

If you get warning "Access token is depreciated". Please add or replace your code line by this two lines where you are passing permissions to your app

[FBSession.activeSession closeAndClearTokenInformation]; 

NSArray *permissions = [NSArray arrayWithObjects:@"email", nil];

If u are doing all the thing right then please check "status" value. If it is 257 then please enable your app in your IPhone facebook settings.

Here is the code that can help you to understand in better way

   [FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler:^(FBSession *session,
                                                                                                     FBSessionState status, NSError *error)
     {
      if (error)
      {
              NSLog(@"error===%@   status====%u",error,status);
              // Handle errors
                 [self handleAuthError:error];
         }
         else if (FB_ISSESSIONOPENWITHSTATE(status))
         {
             [self getData];
         }
     }];


-(void)handleAuthError:(NSError *)error{
    NSString *alertMessage, *alertTitle;

    if (error.fberrorShouldNotifyUser) {
        // If the SDK has a message for the user, surface it.
        alertTitle = @"Something Went Wrong";
        alertMessage = error.fberrorUserMessage;
    } else if (error.fberrorCategory == FBErrorCategoryUserCancelled) {
        // The user has cancelled a login. You can inspect the error
        // for more context. For this sample, we will simply ignore it.
        NSLog(@"user cancelled login");
    } else {
        // For simplicity, this sample treats other errors blindly.
        alertTitle  = @"Unknown Error";
        alertMessage = @"Error. Please try again later.";
        NSLog(@"Unexpected error:%@", error);
    }

    if (alertMessage) {
        [[[UIAlertView alloc] initWithTitle:alertTitle
                                    message:alertMessage
                                   delegate:nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil] show];
    }
}

I hope it would work.

There is also a case when you have 2 or more items in the URL types array in your info.plist. The Facebook related item should be the first, otherwise you get the error 2. This is probably a Facebook SDK bug.

This worked for me:

Go to the settings app of your iPhone. Open your Facebook Settings Scroll down to your app and make sure your app allows facebook interaction.

Download Facebook new version and it should work. I had same error with sdk version 3.13.1.Then, I replaced it with sdk version 3.14.1. Then, it worked for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!