Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
552 views
in Technique[技术] by (71.8m points)

objective c - iOS Facebook SDK Error Domain com.facebook.sdk Code 2 and Code 7

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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...