简体   繁体   中英

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. I tried to set up Facebook Login. No problems with the Facebook sdk and I can log in successfully. However, when the credential returned by Facebook sdk is used as a parameter of FirebaseAuth.DefaultInstance.SignInWithCredentialAsync , it returns internal error.

在此处输入图片说明

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:

在此处输入图片说明

When I test it on my Android device, it comes out an error message g_methods_cached only.

在此处输入图片说明

Can anyone help?

PS Here is another question asked yesterday and I don't know if it is relevant. FirebaseAuthWebException not found. Please verify the AAR

Oh, I have made a silly mistake!

In the Facebook Developer page, there is the App Secret in Setting > Basic. And it has to be added into Firebase Console with the App ID. No problem right now. And then......

I just copied the App Secret without showing and pasted into Firebase Console.

Which means I have set 8 black dots (●●●●●●●●) as my App Secret in my Firebase Console. I know it is too silly. But just in case there is someone careless like me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM