问题
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:
- Compare my app id in .plist file with FB bundle id. They are the same!!!
- My app is not in a sandbox mode!
- If I change from
[FBSession openActiveSessionWithReadPermissions:permissions
to[FBSession openActiveSessionWithPermissions:permissions
- it works. But it is deprecated.
回答1:
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.
回答2:
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.
回答3:
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.
回答4:
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!
来源:https://stackoverflow.com/questions/20657780/ios-facebook-sdk-error-domain-com-facebook-sdk-code-2-and-code-7