Facebook SDK 原生登录错误
Posted
技术标签:
【中文标题】Facebook SDK 原生登录错误【英文标题】:Facebook SDK native login error 【发布时间】:2014-10-14 00:25:43 【问题描述】:注意:我正在遵循来自 Native Facebook Login stopped working after SDK update to 3.14 的本地登录建议。
错误如下:
2014-10-13 20:03:27.378 注册[1916:407643] 错误 Domain=com.facebook.sdk Code=9 "未授予访问权限 脸书账号。验证设备设置。” UserInfo=0x1753c630 NSLocalizedDescription=尚未授予 Facebook 访问权限 帐户。验证设备设置。, NSLocalizedFailureReason=Access has 未授予 Facebook 帐户。验证设备设置。
这是下面的代码:
// RegistrationManager.m
- (void)setupFacebook
FBSessionStateHandler completionHandler = ^(FBSession *session, FBSessionState status, NSError *error)
[self sessionStateChanged:session state:status error:error];
;
if ([FBSession activeSession].state == FBSessionStateCreatedTokenLoaded)
// we have a cached token, so open the session
[[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent
completionHandler:completionHandler];
else
[self clearAllUserInformation];
// create a new facebook session
FBSession *fbSession = [[FBSession alloc] initWithPermissions:@[@"public_profile"]];
[FBSession setActiveSession:fbSession];
[fbSession openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent completionHandler:completionHandler];
- (void)clearAllUserInformation
[FBSession.activeSession closeAndClearTokenInformation];
[FBSession renewSystemCredentials:^(ACAccountCredentialRenewResult result, NSError *error)
NSLog(@"%@", error);
];
[FBSession setActiveSession:nil];
// RegistrationViewController.m
- (IBAction)loginButtonPressed:(id)sender
// If the session state is any of the two "open" states when the button is clicked
if (FBSession.activeSession.state == FBSessionStateOpen
|| FBSession.activeSession.state == FBSessionStateOpenTokenExtended)
// Close the session and remove the access token from the cache
// The session state handler (in the app delegate) will be called automatically
[FBSession.activeSession closeAndClearTokenInformation];
// If the session state is not any of the two "open" states when the button is clicked
else
FBSessionStateHandler completionHandler = ^(FBSession *session, FBSessionState status, NSError *error)
[registrationManager sessionStateChanged:session state:status error:error];
;
// create a new facebook session
FBSession *fbSession = [[FBSession alloc] initWithPermissions:@[@"public_profile"]];
[FBSession setActiveSession:fbSession];
[fbSession openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent completionHandler:completionHandler];
当我点击按钮时,它只是说
2014-10-13 20:03:29.560 注册[1916:407643] 会话关闭 2014-10-13 20:03:29.561 注册 [1916:407643] 用户注销。 2014-10-13 20:03:29.573 注册[1916:407643] 用户注销。
【问题讨论】:
【参考方案1】:这意味着用户曾经在请求权限的弹出窗口中选择了“不允许”。如果他在“设置”中链接了他的 Facebook 帐户,从现在开始,每次他尝试登录时都会显示此错误。它不会回退到 Safari 或其他任何东西,只是显示此错误。用户需要进入 Settings -> Facebook 并将您的应用的滑块设置为 ON。
【讨论】:
以上是关于Facebook SDK 原生登录错误的主要内容,如果未能解决你的问题,请参考以下文章
iOS Facebook 最新 SDK 无法通过原生 App 但浏览器登录