Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The operation couldn’t be completed. (com.facebook.sdk error 2.) ios6

Hi i am ussing ios6 for facebook login and i am getting this error as native popup

The operation couldn’t be completed. (com.facebook.sdk error 2.)

This is the scenario ive used. (I am running this on simularor)

I have logged in to the facebook app through settings and i tried to login to my app and its working fine.

Then i logged out of the facebook from settings and logged in again with different user. Then i tried to login to the app. I am getting this error.

I tried loging out of the app using the command

[FBSession.activeSession closeAndClearTokenInformation];

But no use.

The bundle identifier in the facebook app is same as in my ios app.

this is the code i used to login

NSArray *permissions = [[NSArray alloc] initWithObjects:@"email", nil];
    [FBSession openActiveSessionWithReadPermissions:permissions
                                       allowLoginUI:YES
                                  completionHandler:
     ^(FBSession *session,
       FBSessionState state, NSError *error) {
         [self sessionStateChanged:session state:state error:error];
     }];

Any help is appreciated.

This is the error i am getting

Domain=com.facebook.sdk Code=2 "The operation couldn’t be completed. (com.facebook.sdk error 2.)" UserInfo=0x9535330 {com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:SystemLoginDisallowedWithoutError, com.facebook.sdk:ErrorSessionKey=, expirationDate: (null), refreshDate: (null), attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(null)>}

NOTE I got the same error on a different occation. At that time it was a bug in my code

Instead of giving permission as

NSArray *permissions = [[NSArray alloc] initWithObjects:@"email",@"birthday", nil];

i was wrongly doing it as

NSArray *permissions = [[NSArray alloc] initWithObjects:@"email,birthday", nil];

SOLUTION Even after correcting the code, I was getting the same error. I have to logout and login the facebook from ios settings screen. Once i did that the correct code never caused any problem. Note that the problem only occured on the device that previously executed the buggy code. Note sure what caused the problem, Hope this info helps someone

like image 498
M S Avatar asked Apr 05 '13 10:04

M S


People also ask

How can I update my Facebook SDK?

Login into Facebook and navigate to https://developers.facebook.com/apps/ Select the App you want to upgrade (you might have access to multiple apps) Click Settings > Advanced. Select the latest version under the Upgrade API Version section for both “Upgrade All Calls” and “Upgrade Calls for App Roles”

What is the Facebook SDK?

The Facebook SDK is a set of software components that developers can include in their mobile app to understand how people use the app, run optimized marketing campaigns and enable Facebook login and social sharing. This course helps you understand the purpose of the Facebook SDK and App Events for Android and iOS.


4 Answers

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.

This could happen on any device, therefore in your app you will have to make sure to handle this error correctly. I reckon you give the user feedback why Login With Facebook failed and ask the user to check their Facebook settings on their device.

 - (void)facebookSessionStateChanged:(FBSession *)session state:(FBSessionState)state error:(NSError *)error {     switch (state) {         case FBSessionStateOpen:             // handle successful login here         case FBSessionStateClosed:         case FBSessionStateClosedLoginFailed:             [FBSession.activeSession closeAndClearTokenInformation];              if (error) {                 // handle error here, for example by showing an alert to the user                 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Could not login with Facebook"                                                                 message:@"Facebook login failed. Please check your Facebook settings on your phone."                                                                delegate:nil                                                       cancelButtonTitle:@"OK"                                                   otherButtonTitles:nil];                 [alert show];             }             break;         default:             break;     } 
like image 178
Bocaxica Avatar answered Sep 21 '22 16:09

Bocaxica


check your Bundle identifier for your project and you give Bundle identifier for your app which create on developer.facebook.com that they are same or not.

like image 45
Sumit Mundra Avatar answered Sep 21 '22 16:09

Sumit Mundra


Another potential cause for this error: Attempting to get permission for a Facebook app in sandbox mode when the Facebook user is not listed in the app's admins, developers or testers.

like image 27
nephtes Avatar answered Sep 22 '22 16:09

nephtes


I solve my problem by passing nil permission while login.

[FBSession openActiveSessionWithReadPermissions:nil
                                       allowLoginUI:YES
                                  completionHandler:
like image 28
Kirit Vaghela Avatar answered Sep 23 '22 16:09

Kirit Vaghela