1

I am trying to use Parses SDK to make the single sign on for Facebook but when I press the login button I get this error:

Uh oh. An error occurred: Error Domain=com.facebook.sdk Code=2 "The operation couldn’t be completed. (com.facebook.sdk error 2.)" UserInfo=0x1d5bac20 {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)>}

The code when I hit the button is almost the same as in Parse's tutorial

- (IBAction)loginButtonTouchHandler {
    // The permissions requested from the user
    NSArray *permissionsArray = @[ @"user_about_me", @"user_birthday"];

    // Login PFUser using Facebook
    [PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
        [_activityIndicator stopAnimating]; // Hide loading indicator

        if (!user) {
            if (!error) {
                NSLog(@"Uh oh. The user cancelled the Facebook login.");
            } else {
                NSLog(@"Uh oh. An error occurred: %@", error);
            }
        } else if (user.isNew) {
            NSLog(@"User with facebook signed up and logged in!");
        } else {
            NSLog(@"User with facebook logged in!");
        }
    }];
}

I have my facebook app all set and everything.

Any leads?

Daddy
  • 9,045
  • 7
  • 69
  • 98
Andre Cytryn
  • 2,506
  • 4
  • 28
  • 43
  • 1
    Please see this question http://stackoverflow.com/questions/15831610/the-operation-couldnt-be-completed-com-facebook-sdk-error-2-ios6 – Daddy Apr 16 '13 at 18:00

7 Answers7

9

I had the same problem on my device. Same error.

Fix was simple: Settings -> Privacy -> Facebook -> and check your app status there.

Sjoerd Perfors
  • 2,317
  • 22
  • 37
4

I had the same problem on one device (iPhone 5S). The Settings -> Privacy -> Facebook were correct. I had other devices along with the iPhone sim which all worked fine.

Anyway, I tried rebooting which did not fix the issue, also to delete the app and reinstall.

What finally worked was the following:

  1. Turn off the access for the app under Settings -> Privacy -> Facebook.
  2. Try logging into FB from the app. (which fails of course).
  3. Re enable access for the app setting under Settings -> Privacy -> Facebook.
  4. Try logging into FB from the app which now succeeded.

Strange error.

Hope this helps someone.

2

See the answer below. Sometimes strangely enough the switch is turned on. It helps to relogin with Facebook in System preferences.

Mikhail Larionov
  • 676
  • 1
  • 7
  • 11
0

Pass an empty permissions array NSArray *permissionsArray = @[];

Make sure your permissions are set in your facebook app console.

slammer
  • 278
  • 3
  • 9
0

I removed my FB access Key and secret from the parse backend and it worked great.

( Parse bug??)

UKDataGeek
  • 6,338
  • 9
  • 46
  • 63
0

Please makesure you for add at AppDelegate.m

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {

     return [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
}

and add

[FBSDKAppEvents activateApp];

- (void)applicationDidBecomeActive:(UIApplication *)application {
    [FBSDKAppEvents activateApp];
}
benka
  • 4,732
  • 35
  • 47
  • 58
Fajar Pradhana
  • 124
  • 1
  • 2
0

To make it work on Swift 3.1 and iOS 10.3.1, make sure that you have following methods in your app delegate:

Just for Swift 3.1:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
  let configuration = ParseClientConfiguration {
       $0.applicationId = "XXXXX"
       $0.clientKey = "XXXXXX"
       $0.server = "https://yourserverparse.."
   }

   Parse.initialize(with: configuration)
   PFFacebookUtils.initializeFacebook(applicationLaunchOptions: launchOptions)

   return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}

And than:

 func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

    var isHandled:Bool;

    if #available(iOS 9.0, *) {
        isHandled = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[.sourceApplication] as! String!, annotation: options[.annotation])
    } else {
        // Fallback on earlier versions
        isHandled = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)
    }

    return isHandled
}

And than:

func applicationDidBecomeActive(_ application: UIApplication) {
    FBSDKAppEvents.activateApp()
}
Filip Ajdačić
  • 490
  • 6
  • 7