iOS 解析 Facebook 登录错误 308 FBSDKLoginBadChallengeString [英] iOS Parse Facebook Login error 308 FBSDKLoginBadChallengeString

查看:47
本文介绍了iOS 解析 Facebook 登录错误 308 FBSDKLoginBadChallengeString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Parse 在我的 iOS 应用中实现 Facebook 登录.

I'm trying to implement Facebook login in my iOS app, using Parse.

let permissionsArray = ["public_profile", "email"]

PFFacebookUtils.logInInBackgroundWithReadPermissions(permissionsArray)
    { (user: PFUser?, error: NSError?) in

    if let user = user {
        //we logged in!
    }
    else {
        //login error!
    }
}

这在模拟器中运行良好,但不适用于设备.在设备上,我收到此错误:

This works well in the Simulator, but not on the device. On the device, I get this error:

Error Domain=com.facebook.sdk.login Code=308操作无法完成.(com.facebook.sdk.login 错误 308.)

Error Domain=com.facebook.sdk.login Code=308 "The operation couldn’t be completed. (com.facebook.sdk.login error 308.)

错误代码 308 适用于 FBSDKLoginBadChallengeString, "登录响应缺少有效的质询字符串."

Error code 308 is for FBSDKLoginBadChallengeString, "The login response was missing a valid challenge string."

在我在 Facebook 上授权我的应用后,这会被调用:

After I authorise my app on Facebook, this gets called:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}

网址是:

fb1640722449492705://authorize/#state=%7B%22challenge%22%3A%225OKWv3wN%2BEH%2BeQu48Xv6ty%2BRuek%3D%22%2C%22com.facebook_true%22%3C.facebook.sdk%A223_method%22%3A1%2C%220_auth_logger_id%22%3A%22564CD915-2CFC-4989-9AF6-CEA389908D51%22%7D&安培; granted_scopes = user_birthday%2Cpublic_profile&安培; denied_scopes =安培; signed_request = c8SBBDeaNpF-R_XTYx4LRA0BWm5p9IwXDr8M4nL3YXI&安培;访问_token=CAAXUOnbG6uEBANtAd9DzWBSu4LLOEcPsu86Ny0Ir

是的,我遵循了Parse 的 Facebook 登录指南中的所有内容(确保所有包 ID 匹配,实现所有必需的 AppDelegate 方法等).

Yes, I followed everything in Parse's Facebook login guide (made sure that all bundle IDs match, implemented all required AppDelegate methods, etc).

这个错误到底是什么意思,你是如何解决的?

What exactly does this error mean and how do you solve it?

推荐答案

已修复.此问题是由使用 Parse 使用 FBSDKLoginButton 登录引起的.

Fixed it. This issue was caused by logging in with Parse and with FBSDKLoginButton.

这是我在做什么:

//in my UI setup code:
let fbLoginButton = FBSDKLoginButton()
fbLoginButton.addTarget(self, action: "fbButtonTouched:", forControlEvents: UIControlEvents.TouchUpInside)

....

func fbButtonTouched() {
    let permissionsArray = ["public_profile", "email"]

    PFFacebookUtils.logInInBackgroundWithReadPermissions(permissionsArray)
        { (user: PFUser?, error: NSError?) in

            if let user = user {
                //we logged in!
            }
            else {
                //login error!
            }
    }
}

我发现(艰难的)点击一个FBSDKLoginButton试图登录用户!无需同时使用 PFFacebookUtils.logInInBackgroundWithReadPermissions 登录用户.所以我刚刚摆脱了 fbButtonTouched() 并且我可以愉快地登录了.

I found out (the hard way) that tapping a FBSDKLoginButton attempts to log the user in! There was no need to also log the user in using PFFacebookUtils.logInInBackgroundWithReadPermissions. So I just got rid of fbButtonTouched() and I could happily log in.

所以发生的事情是我同时尝试了两次登录,模拟器对此感到满意,但设备却对此不满意.

So what happened was that I was attempting two logins at the same time, which the simulator was happy with, but not the device.

如果你想知道为什么,那是因为它收到了登录认证挑战 与它期望的不对应 因为它在发送了第二次登录尝试中的一次后收到了第一次登录尝试中的一次,因此正在等待第二次登录尝试' 身份验证挑战.

If you want to know why, it's because the login authentication challenge it received did not correspond to the one it was expecting because it received the one from the first log in attempt after it had sent the one from the second log in attempt and was therefore waiting for the second log in attempts' authentication challenge.

FBSDKLoginButton 的文档没有目前提到任何关于点击它启动登录流程的事实,并且因为它是UIButton的子类,你会认为你应该addTarget 并自己实现登录流程.并且同时登录两次会导致误导FBSDKLoginBadChallengeString.灾难的秘诀...

The documentation for FBSDKLoginButton doesn't currently mention anything about the fact that tapping it initiates the log in flow, and because it's a subclass of UIButton, you'd think that you ought to addTarget to it and implement the login flow yourself. And having two logins at the same time leads to a misleading FBSDKLoginBadChallengeString. Recipe for disaster...

文档已相应更新:

FBSDKLoginButton[FBSDKAccessToken currentAccessToken] 一起确定要显示的内容,并在点击时自动启动身份验证(即,您不需要手动订阅操作目标).

FBSDKLoginButton works with [FBSDKAccessToken currentAccessToken] to determine what to display, and automatically starts authentication when tapped (i.e., you do not need to manually subscribe action targets).

(我的重点)

这篇关于iOS 解析 Facebook 登录错误 308 FBSDKLoginBadChallengeString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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