我有一个支持 Twitter 登录的 iOS Firebase 应用,但有时 signIn(with: credential
调用会随机失败,我不知道为什么。
首先,用户使用 Twitter 登录(永远不会失败),然后我使用 Twitter session 获取凭据,然后我使用这些凭据登录 Firebase,但有时会失败。
这是完整的代码
func twitterLogin(_ doneescaping (_ user: FIRUser?, _ err: Error?) -> Void) {
Twitter.sharedInstance().logIn() { session, error in
guard error == nil else {
done(nil, error)
return
}
let credential = FIRTwitterAuthProvider.credential(withToken: session!.authToken, secret: session!.authTokenSecret)
FIRAuth.auth()?.signIn(with: credential, completion: { (signUser, error) in
//User is signed in
// ERROR OCCURS HERE. ANY HELP WOULD BE GREATLY APPRECIATED
done(signUser, error)
})
}
}
这是我收到的确切错误消息。
UserInfo={NSUnderlyingError=0x600000442c10 {Error Domain=FIRAuthInternalErrorDomain Code=3 "(null)" UserInfo={FIRAuthErrorUserInfoDeserializedResponseKey={
code = 400;
errors = (
{
domain = global;
message = "Network error while to fetch VERIFY_CREDENTIAL from TWITTER.";
reason = invalid;
}
);
message = "Network error while to fetch VERIFY_CREDENTIAL from TWITTER.";
}}}, error_name=ERROR_INTERNAL_ERROR, NSLocalizedDescription=An internal error has occurred, print and inspect the error details for more information.})
我尝试专门搜索我收到的错误消息“从 TWITTER 获取 VERIFY_CREDENTIAL 时出现网络错误。”但我找不到任何解决方案。我发现了一些我认为是日文的帖子,但我无法理解他们的解决方案。
我什至在这里查看了 Firebases iOS Auth 错误
https://firebase.google.com/docs/auth/ios/errors
但是错误键 FIRAuthErrorUserInfoDeserializedResponseKey 甚至没有被列为 signInWithCredential:completion:
我看到了同样的错误。 codepen 中的示例:
https://codepen.io/mosse/pen/KmGMap
<button class="login">login</button>
<script src="https://www.gstatic.com/firebasejs/4.0.0/firebase.js"></script>
<script>
var config = {
apiKey: "AIzaSyDfJ5KuDofcZpahzl4H3XTl4f6R65gUyrQ",
authDomain: "authtest-3a944.firebaseapp.com",
projectId: "authtest-3a944",
};
firebase.initializeApp(config);
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".login").click(function(){
var providerObj = new firebase.auth.TwitterAuthProvider();
firebase.auth().signInWithPopup(providerObj)
.then(result => {
console.log('success')
console.log(result.user)
})
.catch( err => {
console.log('failure')
console.log(err.message)
})
});
});
</script>
关于使用 Twitter 凭据登录 Firebase 身份验证的 iOS 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43966338/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |