10

I am developing the application which allow user to login via Facebook (using Facebook SDK for it). The error appears when a user has already logged in Facebook in iPhone settings. If not - all work correctly.

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

I've already tried to set permissions as nil array - nothing changed.

The log is:

Error Domain=com.facebook.sdk Code=2 "The operation couldn’t be completed.
(com.facebook.sdk error 2.)" UserInfo=0x1552c6c0 
{com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:SystemLoginDisallowedWithoutError,
com.facebook.sdk:ErrorSessionKey=<FBSession: 0xabe8100, state: FBSessionStateClosedLoginFailed,
loginHandler: 0x0, appID: APPIDHERE, urlSchemeSuffix: ,
tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0x14b8f3d0>,
expirationDate: (null), refreshDate: (null),
attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(null)>}

Sometimes the error with Code 7 is appears too. I have read almost all topics related to this error.

My steps were:

  1. Compare my app id in .plist file with FB bundle id. They are the same!!!
  2. My app is not in a sandbox mode!
  3. If I change from [FBSession openActiveSessionWithReadPermissions:permissions to [FBSession openActiveSessionWithPermissions:permissions- it works. But it is deprecated.
Amal Murali
  • 75,622
  • 18
  • 128
  • 150
Artem Z.
  • 1,243
  • 2
  • 14
  • 36
  • http://stackoverflow.com/questions/12838118/facebook-authorization-fails-on-ios6-when-switching-fb-account-on-device – Mahesh Dec 18 '13 at 12:09
  • I've said I read a lot. The only 1 thing is works for me, but now it is deprecated. – Artem Z. Dec 18 '13 at 12:11
  • @ArtemZ. try with this openActiveSessionWithPublishPermissions instead of read – Minkle Garg Dec 18 '13 at 12:38
  • @MinkleGarg I've tried `[FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience: FBSessionDefaultAudienceFriends`. The error is still alive. – Artem Z. Dec 18 '13 at 13:14
  • @ArtemZ. have you solved the issue? – Minkle Garg Dec 19 '13 at 06:28
  • @MinkleGarg Yes, At the bottom of the answer – Artem Z. Dec 19 '13 at 06:58
  • @ArtemZ.: Please post the solution as answer and mark it as accepted so future visitors also might benefit from your solution. Thanks! – Amal Murali Dec 28 '13 at 14:35
  • @ArtemZ.- Please provide me the steps how you are doing this? – iEinstein Mar 10 '14 at 15:30
  • @iEinstein Yes, sure. My steps were: check if my app is not in a sandbox mode. Add `[FBAppCall handleOpenURL:url sourceApplication:sourceApplication];` inside `-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation` in my appDelegate. And I've set correctly app id in my plist file. Hope it will be helpful :) – Artem Z. Mar 11 '14 at 05:10
  • @ArtemZ.- I have also implemented this but didn't help. You you do some chat with me here or skype my id is ashumishra224 at skype – iEinstein Mar 11 '14 at 05:47
  • @iEinstein I consider that I couldn't help you man, I'm newbie in iOs and facebook too. You have to ask a new question – Artem Z. Mar 11 '14 at 06:16
  • Yeah but the same problem i have as you had I hope you can help me out – iEinstein Mar 11 '14 at 06:40
  • @ArtemZ _Please help me if you know something about it – iEinstein Mar 11 '14 at 08:07
  • @iEinstein Here is 2 screenshots. Whitespace means that these fields are required. http://s29.postimg.org/y6urp8grr/2014_03_11_12_22_35.png http://s27.postimg.org/5na6w734z/2014_03_11_12_22_54.png – Artem Z. Mar 11 '14 at 08:26
  • In your first screen you are using namespace but I am not using it. Is it necessary? – iEinstein Mar 11 '14 at 08:49
  • All the details of mine is same as you. Can we discuss it on chat? – iEinstein Mar 11 '14 at 08:50
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/49464/discussion-between-artem-z-and-ieinstein) – Artem Z. Mar 11 '14 at 10:00
  • It could be that the app is in sandbox mode and the facebook profile does not have access to the app. – C0D3 Oct 05 '14 at 15:52

4 Answers4

13

Yes, after you see this error, if you go to Settings, you will see that the setting for this app is turned "OFF". But the problem in this case is that the user was never prompted to allow access -- i.e. the setting was turned to OFF automatically on first time access. If the user was asked, then of course that is understandable, but this is not the case (it's as if the SDK silently and automatically pressed Don't Allow for the user). That's why this is a problem.

Before you read any further, I want to note that once the setting is set, you cannot simply repeat the process to test it, because once the setting is set, it will never ask the user (even deleting and reinstalling the app does not help). To test this issue, you need to reset the permissions by going to Settings -> General -> Reset -> Reset Location & Privacy, before you can try to replicate this again.

From testing, I've discovered that if you have offline_access in the permissions you are requesting for the first time, then it will give this login error (and not prompt the user and set the permission to OFF). The SDK does not check and tell you that this permission is not allowed; it just fails to login.

Mahesh
  • 1,472
  • 1
  • 9
  • 16
  • I was facing the same issue and your answer solved it. Is there any way this can be solved from developer end. – glo Apr 17 '14 at 09:12
  • 1
    Resetting Location & Privacy did not allow me to reproduce the original permissions request. – ashack May 27 '14 at 19:51
3

This is how I got mine to work- Pass it an empty permissions array.

NSArray *permissionsArray = @[];

However, make sure you have the permissions you want set up in my facebook app page. I only needed the default one so I was okay.

I have a feeling that facebook changed it's server side code. My app was working fine, and then my FB login broke.

Kirit Modi
  • 23,155
  • 15
  • 89
  • 112
slammer
  • 278
  • 3
  • 9
0

I think that these codes are vague enough that there will be lots of different things.

In the end I found that the problem was that my app bundle ID hadn't been updated when I had prepped my app for the app store. Login in to your Facebook developers account and make sure the app ID is correct.

sam_smith
  • 6,023
  • 3
  • 43
  • 60
0

Check that you pasted in the Facebook XML into your Info.plist correctly! (as seen here)

<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>fb{your-app-id}</string>
    </array>
  </dict>
</array>
<key>FacebookAppID</key>
<string>{your-app-id}</string>
<key>FacebookDisplayName</key>
<string>{your-app-name}</string>
<key>LSApplicationQueriesSchemes</key>
<array>
  <string>fbapi</string>
  <string>fb-messenger-api</string>
  <string>fbauth2</string>
  <string>fbshareextension</string>
</array> 

I forgot to omit the curly brackets, and instead replaced the inner text, yielding the error this post references. Make sure you replace the "{your-app-id}" entirely!

Dane Jordan
  • 1,071
  • 1
  • 17
  • 27