2

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!

Community
  • 1
  • 1
Tony
  • 10,088
  • 20
  • 85
  • 139

1 Answers1

2

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).

garrettmurray
  • 3,338
  • 1
  • 25
  • 23
  • I changed it to publish_action. I had no luck though. Any other ideas? The bundle ID is correct.I tried both with the app in sandbox and live. – Tony Aug 05 '13 at 23:23
  • You can't use `publish_action` in that request—`publish_action` is a WRITE permission, and you're using READ permissions there. You need to remove that permission entirely and do that later in a separate request per the SDK. – garrettmurray Aug 05 '13 at 23:25
  • You are right. I removed and it worked (after two days trying everything). So THANK YOU. Now I have a new problem. I used to obtain a token that allowed me to write to the timeline from a backend server. How can I do that now???? – Tony Aug 05 '13 at 23:33
  • I used to send the token to the server after the login. I cannot do that now I think. – Tony Aug 05 '13 at 23:34
  • You can still do that, but first you need to do the second auth request in your app. You need to do the requestNewPublishPermissions bit first from the Facebook SDK, and then you'll have a fully-useful token. – garrettmurray Aug 05 '13 at 23:40