在设备上切换FB帐户时,Facebook授权在iOS6上失败

我正在使用Facebook SDK 3.1.1在我的iOS应用程序中实现FB Connect。 这种情况很好地适用于新的FB集成(在iOS上login)或通过web视图回退到正常授权(我没有在这两种情况下安装本地Facebook应用程序)的情况。 我在iOS级别切换帐户时发生问题。 注销并使用其他FB用户帐户login。

login/授权我执行:

[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:allowLoginUI completionHandler:^(FBSession *session, FBSessionState state, NSError *error) { [self sessionStateChanged:session state:state error:error]; }]; 

如果每次都得到FBSessionStateClosedLoginFailed,即使在达到状态时执行closeAndClearTokenInformation

 - (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error { NSLog(@"Session State Changed: %u", [[FBSession activeSession] state]); switch (state) { case FBSessionStateOpen: break; case FBSessionStateClosed: case FBSessionStateClosedLoginFailed: NSLog(@"FBSessionStateClosedLoginFailed ERROR: %@", [error description]); [[FBSession activeSession] closeAndClearTokenInformation]; break; default: break; } 

但是,每次重试都会收到相同的状态。 我的日志说:

 FBSDKLog: FBSession **INVALID** transition from FBSessionStateCreated to FBSessionStateClosed FBSDKLog: FBSession transition from FBSessionStateCreated to FBSessionStateCreatedOpening FBSDKLog: FBSession transition from FBSessionStateCreatedOpening to FBSessionStateClosedLoginFailed Session State Changed: 257 FBSessionStateClosedLoginFailed TOKEN: (null) FBSessionStateClosedLoginFailed ERROR: Error Domain=com.facebook.sdk Code=2 "The operation couldn't be completed. (com.facebook.sdk error 2.)" UserInfo=0xb24cc20 {com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:ErrorLoginFailedReason} 

任何人都可以重现这个或有任何想法问题可能在哪里?

另一个答案给出了一种手动与服务器重新同步设备的方法。 我定义了一个名为fbRsync的方法来调用这个代码。 确保在你的实现文件中input#import <Accounts/Accounts.h>然后定义这个方法:

 -(void)fbResync { ACAccountStore *accountStore; ACAccountType *accountTypeFB; if ((accountStore = [[ACAccountStore alloc] init]) && (accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook] ) ){ NSArray *fbAccounts = [accountStore accountsWithAccountType:accountTypeFB]; id account; if (fbAccounts && [fbAccounts count] > 0 && (account = [fbAccounts objectAtIndex:0])){ [accountStore renewCredentialsForAccount:account completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) { //we don't actually need to inspect renewResult or error. if (error){ } }]; } 

}

然后我调用fbResync如果openActiveSessionWithReadPermissions产生一个错误:

 [FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState state, NSError *error) { if(error) { NSLog(@"Session error"); [self fbResync]; [NSThread sleepForTimeInterval:0.5]; //half a second [FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState state, NSError *error) { [self sessionStateChanged:session state:state error:error]; }]; } else [self sessionStateChanged:session state:state error:error]; }]; 

半秒钟的延迟可能是不必要的,但是它现在给了我一个想法。

这似乎为我解决了这个问题。 我现在可以在Facebook帐户之间切换,并且可以login。

我有同样的问题。 检查您的FB应用程序是否在设置 – > Facebook中启用。 我被禁用(即使我不记得禁用它),一旦我启用它,它是固定的。

在我的testing过程中,我添加并删除了我的FB应用程序几次从我的FB帐户,这是我的iPhone链接。 这也许可以解释为什么,神奇的是,我的应用程序被禁用。

在与fb sdk 3.1.1的ios 6中。 请在“[FBSessio openActiveSessionWithReadPermissions …”方法中将权限parameter passing为“nil或email”。 在这里,我的代码是伟大的。

 #define IOS_NEWER_OR_EQUAL_TO_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 6.0 ) -(void)showFBLogin { [FBSession.activeSession closeAndClearTokenInformation]; NSArray *permissions = [NSArray arrayWithObjects:@"email, publish_actions, publish_stream", nil]; #ifdef IOS_NEWER_OR_EQUAL_TO_6 permissions = nil; or NSArray *permissions = [NSArray arrayWithObjects:@"email",nil]; #endif NSLog(@"\npermissions = %@", permissions); [FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler: ^(FBSession *session, FBSessionState state, NSError *error) { NSLog(@"\nfb sdk error = %@", error); switch (state) { case FBSessionStateOpen: [[FBRequest requestForMe] startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) { if (!error) { //success } }]; break; case FBSessionStateClosed: //need to handle break; case FBSessionStateClosedLoginFailed: //need to handle break; default: break; } }]; } 

我在使用iOS7.1的3.1.3 FB SDK上遇到同样的问题。 我在这里find一个解决scheme。 希望它帮助!
我在这里试过所有的答案。
@loganathan无权限,@ill_always_be_a_warriors fbResync。
所有这些都不适合我。

但是当我在iPhone 7.1模拟器中启动相同的代码时,我发现它会工作的很好
(没有SSO“单点login”)

相同的代码在老版本的iOS FB SDK上运行良好(不确定哪个版本,但不是3.13)
(但尝试login时不会显示SSO)

所以,我尝试重写一个示例问题。 我在这里发现了几个不同。
1. https://developers.facebook.com/docs/ios/getting-started添加新的FacebookDisplayName
2.我修改了我的BundleID for iTune connect,但是我没有更新回Faceboook App Dev

修改这些设置后,它可以在我的iOS应用程序上使用SSOfunction。
希望它帮助!

你有没有尝试RenewSystemCredential方法? 看看这个post:

Facebook iOS SDK的extendAccessToken不工作 – fbDidExtendToken没有被调用

我得到了同样的错误。 但是我使用@ill_always_be_a_warriors方法: -(void)fbResync但不适用于我。

我终于发现这是我的权限问题,我删除了offline_access权限,它的工作原理,希望它有助于某人。