[英]Unity - SignInWithCredentialAsync causes internal error when using Firebase with Facebook Login
I am a Unity programmer and I am using Firebase to manage user accounts. 我是Unity程序员,正在使用Firebase来管理用户帐户。 I tried to set up Facebook Login. 我试图设置Facebook登录名。 No problems with the Facebook sdk and I can log in successfully. Facebook sdk没问题,我可以成功登录。 However, when the credential returned by Facebook sdk is used as a parameter of FirebaseAuth.DefaultInstance.SignInWithCredentialAsync , it returns internal error. 但是,当将Facebook sdk返回的凭据用作FirebaseAuth.DefaultInstance.SignInWithCredentialAsync的参数时,它将返回内部错误。
And here is my code: 这是我的代码:
void authCallBack(IResult result) {
if (result.Error != null) {
Debug.Log(result.Error);
}
else {
if (FB.IsLoggedIn) {
Debug.Log("Log in successfully.");
AccessToken token = AccessToken.CurrentAccessToken;
Credential credential = FacebookAuthProvider.GetCredential(token.TokenString);
accessToken(credential);
}
else
Debug.Log("not logged in");
}
}
public void accessToken(Credential firebaseResult) {
FirebaseAuth auth = FirebaseAuth.DefaultInstance;
Debug.Log("Auth CurrentUser: " + FirebaseAuth.DefaultInstance.CurrentUser);
if (!FB.IsLoggedIn){
return;
}
if (auth.CurrentUser != null && !string.IsNullOrEmpty(auth.CurrentUser.UserId)){
Debug.Log("CurrentUser ID: " + auth.CurrentUser.UserId);
auth.CurrentUser.LinkAndRetrieveDataWithCredentialAsync(firebaseResult).ContinueWith(task =>
{
if (task.IsCanceled || task.IsFaulted)
{
Debug.LogError("LinkWithCredentialAsync encountered an error: " + task.Exception);
// TODO: Show error message to player
return;
}
FirebaseUser newUser = task.Result.User;
Debug.LogFormat("Credentials successfully linked to Firebase user: {0} ({1})",
newUser.DisplayName, newUser.UserId);
});
} else {
auth.SignInWithCredentialAsync(firebaseResult).ContinueWith(task =>
{
if (task.IsCanceled || task.IsFaulted) {
Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception.InnerExceptions[0].Message);
// TODO: Show error message to player
return;
}
FirebaseUser newUser = task.Result;
Debug.LogFormat("Credentials successfully created Firebase user: {0} ({1})",
newUser.DisplayName, newUser.UserId);
});
}
}
More details in VS Debugging: VS调试中的更多详细信息:
When I test it on my Android device, it comes out an error message g_methods_cached only. 当我在Android设备上对其进行测试时,只会显示一条错误消息g_methods_cached 。
Can anyone help? 有人可以帮忙吗?
PS Here is another question asked yesterday and I don't know if it is relevant. PS:这是昨天又问的另一个问题,我不知道这是否相关。 FirebaseAuthWebException not found. 找不到FirebaseAuthWebException。 Please verify the AAR 请验证AAR
Oh, I have made a silly mistake! 哦,我犯了一个愚蠢的错误!
In the Facebook Developer page, there is the App Secret in Setting > Basic. 在Facebook Developer页面中,在设置>基本中有应用程序秘诀。 And it has to be added into Firebase Console with the App ID. 并且必须使用App ID将其添加到Firebase控制台。 No problem right now. 现在没问题。 And then...... 接着......
I just copied the App Secret without showing and pasted into Firebase Console. 我只是复制了“应用秘密”,没有显示并粘贴到Firebase控制台中。
Which means I have set 8 black dots (●●●●●●●●) as my App Secret in my Firebase Console. 这表示我在Firebase控制台中将8个黑点(●●●●●●●●)设置为我的应用程序密码。 I know it is too silly. 我知道这太傻了。 But just in case there is someone careless like me. 但是以防万一有人像我这样粗心。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.