【发布时间】:2018-01-19 10:10:00
【问题描述】:
我不了解 firebase 网站上关于统一 firebase facebook 身份验证的文档。
我在统一论坛上找到了这段代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Facebook.Unity;
using Firebase.Auth;
using UnityEngine.UI;
public class facebookAuthenticator : MonoBehaviour
{
public Text userID;
private FirebaseAuth facebookAuth;
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;
userID.text = tocken.UserId;
Credential credential = FacebookAuthProvider.GetCredential(tocken.TokenString);
}
else
Debug.Log("log 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);
});
}
}
我对如何调用它感到困惑。 在执行此代码之前我必须采取哪些步骤?我该怎么称呼它?我是否只需将其附加到按钮并让用户输入字段填写?请帮忙,谢谢。
【问题讨论】:
标签: c# facebook firebase unity3d firebase-authentication