Facebook 登录 - 如果存在用户帐户(并且未安装应用程序)登录失败

2024-05-24

我刚刚在测试我的应用程序时发现了这个问题,它真的开始让我烦恼。那么环境是这样的:

  • 没有安装 Facebook 应用程序
  • 用户登录 iOS 系统帐户(在设置 -> Facebook 下)

当我的应用程序第一次尝试对用户进行身份验证时,它会提供这面文本墙:(我尝试稍微清理一下)

2014-01-30 15:20:31.439 Unifeed[2140:70b] Session is <FBSession: 0xb74f9e0, state:         
FBSessionStateClosedLoginFailed, 
loginHandler: 0x0, appID: *************, urlSchemeSuffix: ,    
 tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0xb73bd90>,
 expirationDate: (null),     
refreshDate: (null), attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(null)>

2014-01-30 15:20:31.440 Unifeed[2140:70b] Session closed
2014-01-30 15:20:31.440 Unifeed[2140:70b] User logged out

2014-01-30 15:20:31.441 Unifeed[2140:70b] Error occured Error Domain=com.facebook.sdk Code=2    
"The operation couldn’t be completed. (com.facebook.sdk error 2.)"
UserInfo=********  
{com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:SystemLoginCancelled,    
com.facebook.sdk:ErrorInnerErrorKey=Error Domain=com.apple.accounts Code=7 "The operation 
couldn’t be completed. (com.apple.accounts error 7.)", 
com.facebook.sdk:ErrorSessionKey=<FBSession: 0xb74f9e0, state: FBSessionStateClosedLoginFailed,   
loginHandler: 0x0, appID: ************, urlSchemeSuffix: 
, tokenCachingStrategy:<FBSessionTokenCachingStrategy: 
0xb73bd90>, expirationDate: (null), refreshDate: (null), 
attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(null)>}

2014-01-30 15:20:31.441 Unifeed[2140:70b] User cancelled login
2014-01-30 15:20:31.445 Unifeed[2140:70b] User logged out

我知道这有点令人困惑,但我的看法是它出错了,因为它认为用户取消了登录过程。问题是我从来没有看到小弹出窗口询问我是否要登录或接受权限......所以我将 Facebook 应用程序添加到手机上并且它起作用了......好吧,那太好了,但是如果我有一个用户没有应用程序,但他们在手机上登录了 FB....有人有什么想法吗?

我的身份验证代码如下:(几乎只是从FB网站进行了一些修改)

- (void) facebookSessionChange {
// 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 {
    // Open a session showing the user the login UI
    [FBSession openActiveSessionWithReadPermissions:permissions
                                       allowLoginUI:YES
                                  completionHandler:
     ^(FBSession *session, FBSessionState state, NSError *error) {
         [self sessionStateChanged:session state:state error:error];
     }];
}
 }

 - (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error
 {

NSLog(@"Session is %@", session);
// If the session was opened successfully
if (!error && state == FBSessionStateOpen){
    NSLog(@"Session opened");
    // Show the user the logged-in UI
    [self userLoggedIn];
    return;
}
if (state == FBSessionStateClosed || state == FBSessionStateClosedLoginFailed){
    // If the session is closed
    NSLog(@"Session closed");
    // Show the user the logged-out UI
    [self userLoggedOut];
}

// Handle errors
if (error){
    NSLog(@"Error occured %@", error);
    if ([FBErrorUtility shouldNotifyUserForError:error] == YES){
        NSLog(@"Error occured %@", error);
    } else {

        // If the user cancelled login, do nothing
        if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryUserCancelled) {
            NSLog(@"User cancelled login");

            // Handle session closures that happen outside of the app
        } else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryAuthenticationReopenSession){
            NSLog(@"Session is no longer valid");

        } else {
            //Get more error information from the error
            NSDictionary *errorInformation = [[[error.userInfo objectForKey:@"com.facebook.sdk:ParsedJSONResponseKey"] objectForKey:@"body"] objectForKey:@"error"];
            NSLog(@"Error occured : %@", [errorInformation objectForKey:@"message"]);
        }
    }
    // Clear this token
    [FBSession.activeSession closeAndClearTokenInformation];
    // Show the user the logged-out UI
    [self userLoggedOut];
}
}

// Show the user the logged-out UI
- (void)userLoggedOut 
{
    NSLog(@"User logged out");
}

// Show the user the logged-in UI
- (void)userLoggedIn 
{
    NSLog(@"User Logged in");
    [_delegate doneLogginginToFb];
}

我尝试过改变身份验证的方式,但总是遇到同样的问题......有什么想法吗?

Thanks

A


我想我确实在这里重现了您的错误,您的应用程序在设置中被拒绝访问 Facebook 帐户(出于某种原因,也许您单击了“不允许”...) 用户拒绝访问或关闭 Facebook 设置中的开关后,应用程序将不会再次请求权限,并且每次尝试连接时都会失败并显示 FBErrorCategoryUserCancelled 状态。

要解决此问题,请转到设置 > 常规 > 重置,然后重置位置和隐私。 运行您的应用程序后,您应该能够看到请求权限的提示。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Facebook 登录 - 如果存在用户帐户(并且未安装应用程序)登录失败 的相关文章

随机推荐