iOS 解析 Facebook 登录错误 308 FBSDKLoginBadChallengeString
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30643122/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS Parse Facebook Login error 308 FBSDKLoginBadChallengeString
提问by Eric
I'm trying to implement Facebook login in my iOS app, using Parse.
我正在尝试使用 Parse 在我的 iOS 应用程序中实现 Facebook 登录。
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.)
错误域=com.facebook.sdk.login 代码=308 “操作无法完成。(com.facebook.sdk.login 错误 308。)
Error code 308 is for FBSDKLoginBadChallengeString
, "The login response was missing a valid challenge string."
错误代码 308 表示FBSDKLoginBadChallengeString
“登录响应缺少有效的质询字符串”。
After I authorise my app on Facebook, this gets called:
在我在 Facebook 上授权我的应用程序后,它被调用:
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
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).
是的,我遵循Parse 的 Facebook 登录指南中的所有内容(确保所有包 ID 匹配,实现所有必需的 AppDelegate 方法等)。
What exactly does this error mean and how do you solve it?
这个错误究竟是什么意思,你如何解决它?
采纳答案by Eric
Fixed it. This issue was caused by logging in with Parse andwith FBSDKLoginButton
.
修复。这个问题是通过与解析记录引起的,并用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 tappinga 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.
我发现(硬盘的方式),其敲击一个FBSDKLoginButton
试图登录的用户!无需同时登录用户使用PFFacebookUtils.logInInBackgroundWithReadPermissions
. 所以我刚刚摆脱了fbButtonTouched()
,我可以愉快地登录了。
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 expectingbecause 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 anythingabout 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
目前没有提到任何关于点击它启动登录流程的事实,并且因为它是 的子类UIButton
,你会认为你应该addTarget
自己实现登录流程。并且同时进行两次登录会导致误导FBSDKLoginBadChallengeString
。灾难的食谱...
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).
FBSDKLoginButton
用作品[FBSDKAccessToken currentAccessToken]
来确定显示什么,并自动启动窃听时(即你不需要手动订阅行动目标)的认证。
(my emphasis)
(我的重点)
回答by Cuong Lam
回答by loudmouth
I only saw this error when I logged out, then logged back in.
我只在注销时看到这个错误,然后重新登录。
My login and logout code were located in different files, as the relevant UI for login and logout are entirely different, and I had instantiated two separate FBSDKLoginManager instances. Consolidating to only one instance solved the problem for me.
我的登录和注销代码位于不同的文件中,因为登录和注销的相关 UI 完全不同,并且我已经实例化了两个单独的 FBSDKLoginManager 实例。合并到只有一个实例为我解决了这个问题。
回答by ObjSal
I've followed the workaround from totvos and its working for me as well when using FBSDKLoginKit 4.7.1 & FBSDKCoreKit 4.8:
在使用 FBSDKLoginKit 4.7.1 和 FBSDKCoreKit 4.8 时,我遵循了 totvos 的解决方法及其对我的工作:
Workaround...get the app built and copied to the phone, and then start the app from the device (not the debugger). Then, attach the debugger to the running process. This seems to get around whatever timing issue is breaking this, and the various keychain operations appear to work correctly while debugging.
解决方法...构建应用程序并将其复制到手机,然后从设备(而不是调试器)启动应用程序。然后,将调试器附加到正在运行的进程。这似乎解决了破坏它的任何计时问题,并且在调试时各种钥匙串操作似乎都能正常工作。
Reference: https://forums.developer.apple.com/thread/4743#85335
参考:https: //forums.developer.apple.com/thread/4743#85335
Update:
更新:
This workaround didn't work all the time, so I ended up using @coco's answer above: https://stackoverflow.com/a/31480026/877225
此解决方法并非一直有效,因此我最终使用了上面@coco 的答案:https: //stackoverflow.com/a/31480026/877225
回答by Lolloz89
Apparently the only solution that worked for me is to add the Keychain Sharing Entitlement for the target.
显然,唯一对我有用的解决方案是为目标添加钥匙串共享权利。
You can find it in Project_name->target_name->Capabilities->Keychain Sharing
您可以在 Project_name->target_name->Capabilities->Keychain Sharing 中找到它
回答by coco
I found this problem when I upgraded to:
当我升级到以下时,我发现了这个问题:
FBSDKCoreKit 4.4.0
FBSDKLoginKit 4.4.0
FBSDKShareKit 4.4.0.
It went away when I downgraded to:
当我降级为:
FBSDKCoreKit 4.2.0
FBSDKLoginKit 4.1.0
FBSDKShareKit 4.1.0
I haven't had a chance to discover at what point the upgrades cause this - for example, could I have stuck with 4.3.0 for all three?
我还没有机会发现升级是在什么时候导致这种情况的 - 例如,我是否可以为所有三个都坚持使用 4.3.0?
回答by MkVal
Try running your app straight from your device without having to launch it from your Xcode. Then login to Facebook w/o being bothered by 308. After that, you can resume launching from the Xcode to your device w/o the same issue.
尝试直接从您的设备运行您的应用程序,而无需从您的 Xcode 启动它。然后登录 Facebook,没有被 308 打扰。之后,您可以继续从 Xcode 启动到您的设备,没有同样的问题。
This seems an issue between the FB SDK and iOS and not related to Parse. I'd appreciate it if someone could enlighten us on this subject.
这似乎是 FB SDK 和 iOS 之间的问题,与 Parse 无关。如果有人能在这个主题上启发我们,我将不胜感激。
My Xcode's version is 7.1, FB SDK is 4.8.x.
我的 Xcode 版本是 7.1,FB SDK 是 4.8.x。
回答by Markus Rautopuro
I'm using
我正在使用
pod 'FBSDKCoreKit', '~> 4.8.0'
pod 'FBSDKLoginKit', '~> 4.8.0'
pod 'FBSDKShareKit', '~> 4.8.0'
... and had the code 308
problem when I logged out and logged in during the same session. Using [[FBSDKLoginManager alloc] logOut]
or [facebookLoginManager logOut]
(with a persisted manager) just before calling logInWithReadPermissions:
didn't work, but adding
...并且code 308
在我在同一会话期间注销并登录时遇到了问题。在调用之前使用[[FBSDKLoginManager alloc] logOut]
或[facebookLoginManager logOut]
(使用持久管理器)logInWithReadPermissions:
不起作用,但添加
[FBSDKAccessToken setCurrentAccessToken:nil];
[FBSDKProfile setCurrentProfile:nil];
before the logInWithReadPermissions:
call works ok. (Tested in iOS 9.2.)
在logInWithReadPermissions:
通话正常之前。(在 iOS 9.2 中测试。)
回答by Dev-iL
I also had error 308, however I was not using the Parse SDK.
我也有错误 308,但是我没有使用 Parse SDK。
These errors started appearing when I upgraded the Facebook iOS SDK from version 4.0.1
(FacebookSDKs-iOS-20150402
) to one of the newer versions (4.2.0
- FacebookSDKs-iOS-20150528
or 4.3.0
- FacebookSDKs-iOS-20150625
).
当我将 Facebook iOS SDK 从版本4.0.1
( FacebookSDKs-iOS-20150402
)升级到较新版本之一(4.2.0
-FacebookSDKs-iOS-20150528
或4.3.0
- FacebookSDKs-iOS-20150625
)时,这些错误开始出现。
Downgrading the Facebook iOS SDK to version 4.0.1
solved this problem for me.
将Facebook iOS SDK4.0.1
降级到版本为我解决了这个问题。
As a side note: the new versions of the SDK seem to correlate well with the appearance of 308 error posts on SO at the beginning of June.
附带说明:新版本的 SDK 似乎与 6 月初在 SO 上出现的 308 个错误帖子有很好的相关性。
回答by jriskin
Before downgrading, I would try to clear out the local cache. I've had this problem when switching between Facebook accounts. Delete your app, force the Facebook to quit and then re-run everything and see if it persists. There may be a bug where Facebook is passing an old cached key that is no longer valid. Downgrading could be clearing the cache or the older version doesn't have the bug.
在降级之前,我会尝试清除本地缓存。我在 Facebook 帐户之间切换时遇到了这个问题。删除您的应用程序,强制 Facebook 退出,然后重新运行所有内容,看看它是否仍然存在。可能存在一个错误,即 Facebook 正在传递不再有效的旧缓存密钥。降级可能是清除缓存或旧版本没有错误。