简体   繁体   中英

Connect facebook login to firebase in unity

I want in my unity game with firebase facebook login when user login through facebook there user name, email & profile picture save in firebase. I tried from firebase unity login auth docs but i cant get any thing from there. On there docs to difficult to understand for beginners.

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);
    });
}
}

Please help me i am beginner in coding

Image

tocken.UserId This is wrong. Use tocken.TokenString . This will solve your problem. :)

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