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

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

问题描述

我试图在我的iOS应用程序中使用Parse实现Facebook登录。

  let permissionsArray = [public_profile,email] 

PFFacebookUtils.logInInBackgroundWithReadPermissions(permissionsArray)
{(用户:PFUser?,错误:NSError?)在

如果让user = user {
//我们登录!
}
else {
//登录错误!
}
}

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


错误Domain = com.facebook.sdk.login代码= 308操作不能(com.facebook.sdk.login error 308。)


错误代码308用于 FBSDKLoginBadChallengeString ,The登录回复缺少一个有效的挑战字符串。



当我在Facebook上授权我的应用程序后,会被调用:

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

url是:



fb1640722449492705:// authorize /#state =%7B%22challenge% 22%3A%225OKWv3wN%2BEH%2BeQu48Xv6ty%2BRuek%3D%22%2C%22com.facebook.sdk_client_state%22%3Atrue%2C%223_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.eyJhbGdvcml&安培; =的access_token CAAXUOnbG6uEBANtAd9DzWBSu4LLOEcPsu86Ny0Ir



是的,我遵循解析的所有内容Facebook登录指南(确保所有bundle ID匹配,实现所有必需的AppDelegate方法等)。



这个错误是什么意思,怎么解决?

解决方案

修正了此问题是由于使用 FBSDKLoginButton 的Parse 登录。



这是什么我在做:在我的UI设置代码中:
let fbLoginButton = FBSDKLoginButton()
fbLoginButton.addTarget(self,action:fbButtonTouched:,forControlEvents:UIControlEvents.TouchUpInside)

....

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

PFFacebookUtils.logInInBackgroundWithReadPermissions(permissionsArray)
{(用户:PFUser?,错误:NSError?)在

if让user = user {
//我们登录!
}
else {
//登录错误!
}
}
}

我发现方式)点击 a FBSDKLoginButton 尝试记录用户!不需要使用 PFFacebookUtils.logInInBackgroundWithReadPermissions 来记录用户。所以我只是摆脱了 fbButtonTouched(),我可以很高兴地登录。



所以发生了什么事在同一时间尝试两次登录,模拟器很高兴,但不是设备。



如果你想知道为什么,这是因为登录身份验证挑战已收到与之前的相符因为它从第一次登录尝试中收到一个从第二次登录尝试发送一个,因此等待第二次登录尝试身份验证挑战。



<$ c的文档$ c> FBSDKLoginButton 当前没有提及任何关于点击它启动日志流的事实,因为它是<$ c $的子类c> UIButton ,你会认为你应该 addTarget ,并自己实现登录流程。同时进行两次登录会导致一个误导性的 FBSDKLoginBadChallengeString 。编辑:文件已相应更新:



b
$ b

blockquote>

FBSDKLoginButton 使用 [FBSDKAccessToken currentAccessToken] 确定要显示的内容,并自动开始认证(即您不需要手动订阅操作目标)


(我的重点)


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 "The operation couldn’t be completed. (com.facebook.sdk.login error 308.)

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

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)
}

The url is:

fb1640722449492705://authorize/#state=%7B%22challenge%22%3A%225OKWv3wN%2BEH%2BeQu48Xv6ty%2BRuek%3D%22%2C%22com.facebook.sdk_client_state%22%3Atrue%2C%223_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.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImNvZGUiOiJBUURhTXJibGw4Q3dITkd5M0xnQmNkVTNuYWRkeEVoTU5mMmx3eFpZU2IwZl9SU284YXhZdXZaRS02RnA2bU5Cdy1CWkVoRmt2Zk1xX1AxSHltUG00aWhkWE9hYmlvWFBiMnpCYkVnR1RRX3lzZVFIZXdHU19OcmpkNUF6WGtob1dfVE4wTmRrSGk5MzY0V2hFWUJDV0dfcE16RXpQVExHWE13X1dzb0QzZGtITm5fM0tHNjFxUjJyM3RDWVlNQTE4WENpS1dXTHUyM2dIRVhmTXc3ZTQ0M2xDQUtGRl9KSXcyVk1sS01FOTQ4dHQ2U1Fqb0tlVkp4RmJNSEFsWDZFYWxlUnQ2aGRrTGZlU2xuVTV5VjZ1bFhldHkxeEV5RmRDZVFHb2RXQ0dULVVCd3QyM0haY0dxNk8zbnE1cDRNWjNFZ012U2JhSGZyMmF6Wm8xUXk2X2xSQVNWcFlMVDZUdU5wZnMwVkJqNEdSaFEiLCJpc3N1ZWRfYXQiOjE0MzM0MTg2MDksInVzZXJfaWQiOiIxNDM3MzM0ODk5OTIwNDA5In0&access_token=CAAXUOnbG6uEBANtAd9DzWBSu4LLOEcPsu86Ny0Ir

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?

解决方案

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

Here's what I was doing:

//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!
            }
    }
}

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.

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...

EDIT: The documentation has been updated correspondingly:

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).

(my emphasis)

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

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