Facebook登录 - 如果用户帐户(并且未安装应用程序),则登录失败 [英] Facebook Login - If user account is present (and app is not installed) login fails

查看:843
本文介绍了Facebook登录 - 如果用户帐户(并且未安装应用程序),则登录失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在测试我的应用程序时发现了这个问题,这真的让我很烦了。那么环境是什么样的如下所示:

I have just found this issue whilst testing my application and it is really starting to annoy me. So what the environment is like is as follows :


  • 没有安装Facebook应用程序

  • 进入iOS系统帐户(在设置 - > Facebook下)

当我的应用程序第一次尝试验证用户时,它提供了这个墙的文本:(我试过清理一下)

When my app attempts to authenticate the user for the first time it provides this wall of text : ( I tried cleaning it up a little)

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登录在手机....任何人有任何想法?

I know thats slightly confusing but my take on it is its erring out because it thinks the user cancelled the login process. The thing is I never see the little pop up asking me if I want to login or to accept the permissions.... So I added the Facebook app to the phone and it worked... well thats great but what if I have a user with not App but they have FB logged in on the phone.... Anyone have any ideas?

我的验证代码如下:(几乎只是一个从FB网站修改的小)

My code for authentication is as follows : (Pretty much just a little modified from FB website)

- (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];
}

我已经尝试改变我的身份验证方式,但总是遇到同样的问题。 ..任何想法?

I have tried changing the way I authenticate but always run into the same problem... Any ideas?

谢谢

A

推荐答案

我想我在这里重现了你的错误,你的应用程序被拒绝访问Facebook帐户在设置(由于某些原因,也许你点击不允许...)
在用户拒绝访问或关闭Facebook设置中的交换机后,应用程序将不会再次询问该权限,并且每次尝试连接时,它都将失败并显示FBErrorCategoryUserCancelled状态。

I think I did reproduce your error here, your application was denied access to Facebook account in settings (for some reason, maybe you clicked on "don't allow" ...) after the user deny the access or turn off the switch in Facebook settings, the application will not ask again for the permission and every time you will try to connect it will fail with a FBErrorCategoryUserCancelled state.

要解决这个问题,请转到设置>常规>重置,然后重置位置&隐私即可。
运行您的应用程序后,您应该可以看到提示要求权限。

To fix this go to Settings > General > Reset, and then reset the Location & Privacy. After that run your application, you should be able to see the prompt asking for permissions.

这篇关于Facebook登录 - 如果用户帐户(并且未安装应用程序),则登录失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆