我不明白firebase網站上關於統一firebase Facebook身份驗證的文檔。Unity Firebase facebbok身份驗證
我發現了團結論壇驗證碼:
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);
});
}
}
我在我將如何調用此困惑。 執行此代碼之前,我必須執行哪些步驟?我怎麼稱呼它?我只是將它附加到一個按鈕,並給用戶輸入字段填寫?請幫忙,謝謝。
它建議包括在回答必要的內容,而不是使用參考鏈接 – Ibo