繁体   English   中英

Firebase Unity Facebook 登录不返回/保存 email

[英]Firebase Unity Facebook login does not return/save email

我正在使用 Firebase 允许用户通过 Facebook 登录 Unity 游戏。 它工作正常,但我无法使用此参数auth.CurrentUser.Email 此外,email 未存储在 Firebase 身份验证控制台中。 当我使用其他登录方法(例如 email 和 google)时,可以成功存储/访问 email。

这是我的代码:

    public void SignInFacebook()
    {
        var perms = new List<string>() { "public_profile", "email", "user_friends" };
        FB.LogInWithReadPermissions(perms, AuthCallback);
    }

    private void AuthCallback(ILoginResult result)
    {
        if (FB.IsLoggedIn)
        {
            // AccessToken class will have session details
            var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
            // Print current access token's User ID
            Debug.Log(aToken.UserId);
            // Print current access token's granted permissions
            foreach (string perm in aToken.Permissions)
            {
                Debug.Log(perm);
            }

            Credential credential = FacebookAuthProvider.GetCredential(aToken.TokenString);
                auth.SignInWithCredentialAsync(credential).ContinueWithOnMainThread(task => {
                    if (task.IsCanceled)
                    {
                        Debug.LogError("SignInWithCredentialAsync was canceled.");
                        return;
                    }
                    if (task.IsFaulted)
                    {
                        Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                        return;
                    }

                    Firebase.Auth.FirebaseUser newUser = task.Result;
                    Debug.LogFormat("User signed in successfully: {0} - {2} - ({1})",
                        newUser.DisplayName, newUser.UserId, newUser.Email);
                });
        }
        else
        {
            Debug.Log("User cancelled login");
        }
    }

这就是它在控制台中的样子(“-”是应该存储 email 的位置。如果我使用其他登录方法,例如 email 或 google,则 Z0C83F57C786A0B4A39EFAB2371 没有任何问题)

在此处输入图像描述

有人问过类似的问题,有人建议我更改 Firebase 中的Account email 地址设置,以防止使用相同的 email 地址创建多个帐户,但没有解决问题。

谢谢!

如果您的 Facebook 应用程序处于测试模式,您必须从您的 Facebook ID 登录。 Go 到设置,向下滚动,select应用程序和网站,然后单击您的应用程序。 从那里,确保启用 email 地址要求。

在此处输入图像描述

你可以试试这个

private void FacebookAuthCallback(ILoginResult result)
{
    if (FB.IsLoggedIn)
    {
        FB.API("/me?fields=id,name,email", HttpMethod.GET, FacebookGetInfo);
    }
    else
    {
        Debug.Log("User cancelled login");
    }
}

private void FacebookGetInfo(IResult result)
{
    if (result.Error == null)
    {
        if (result.ResultDictionary.ContainsKey("email"))
        {
            string aEmail = result.ResultDictionary["email"].ToString();
            return;
        }
    }
    else
    {
        Debug.Log(result.Error);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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