繁体   English   中英

将Facebook登录名统一连接到Firebase

[英]Connect facebook login to firebase in unity

我想在我的统一游戏中使用Firebase Facebook登录,而当用户通过Facebook登录时,用户名,电子邮件和个人资料图片保存在Firebase中。 我尝试从firebase unity login auth docs尝试,但是我无法从那里得到任何东西。 那里的文档对于初学者来说很难理解。

using UnityEngine;
using Facebook.Unity;
using UnityEngine.UI;
using Firebase.Auth;


public class FacebookManager : MonoBehaviour
{
public Text userIdText;
private FirebaseAuth mAuth;



private void Awake()
{



    if (!FB.IsInitialized)
    {
        FB.Init();
    }
    else
    {
        FB.ActivateApp();
    }
}

public void LogIn()
{
    FB.LogInWithReadPermissions(callback:OnLogIn);


}
private void OnLogIn(ILoginResult result)
{
    if (FB.IsLoggedIn)
    {
        AccessToken tocken = AccessToken.CurrentAccessToken;
        userIdText.text = tocken.UserId;
        Credential credential =FacebookAuthProvider.GetCredential(tocken.UserId);

    }
    else
    {
        Debug.Log("Login Failed");
    }
}

public void accessToken(Credential firebaseResult)
{
    FirebaseAuth auth = FirebaseAuth.DefaultInstance;
    if (!FB.IsLoggedIn)
    {
        return;
    }

    auth.SignInWithCredentialAsync(firebaseResult).ContinueWith(task =>
    {
        if (task.IsCanceled)
        {
            Debug.LogError("SignInWithCredentialAsync was canceled.");
            return;
        }
        if (task.IsFaulted)
        {
            Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
            return;
        }

        FirebaseUser newUser = task.Result;
        Debug.LogFormat("User signed in successfully: {0} ({1})",
            newUser.DisplayName, newUser.UserId);
    });
}
}

请帮助我,我是编码的初学者

图片

tocken.UserId这是错误的。 使用tocken.TokenString 这样可以解决您的问题。 :)

暂无
暂无

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

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