繁体   English   中英

Facebook统一访问令牌到firebase

[英]facebook unity access token to firebase

所以我有我的统一应用程序有点工作。 我现在的问题是: 当我按脚本中的Facebook按钮登录时出现的屏幕

在统一编辑器环境中进行测试时,此标准是什么?

此外,我注意到屏幕要求输入访问令牌。 我真正想做的是访问此令牌并将其传递给Facebook的Firebase身份验证方法。 可以像在authCallBack函数中一样保存它吗? 如果是这样,我是否只是将创建的凭据传递给调用身份验证任务的accessToken方法,或者我完全是全部吗? 任何帮助将不胜感激

这是我的代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Facebook.Unity;
using Firebase.Auth;

public class FacebookHandler : MonoBehaviour {

// Use this for initialization
private void Awake()
{
    FB.Init(setInit, onHideUnity);
}

void setInit()
{
    if (FB.IsLoggedIn)
    {
        Debug.Log("fb is logged in");
    }
    else
        Debug.Log("fb is not logged in");
}

//for whether the game is open or not
void onHideUnity(bool isGameShown)
{
    if (!isGameShown)
    {
        Time.timeScale = 0;
    }
    else
        Time.timeScale = 1;
}

public void fbLogin()
{
    List<string> permissions = new List<string>();

    //asks facebook for the users profile
    permissions.Add("public_profile");
    permissions.Add("email");
    permissions.Add("user_friends");

    FB.LogInWithReadPermissions(permissions, authCallBack);
}

void authCallBack(IResult result)
{
    if (result.Error != null)
    {
        Debug.Log(result.Error);

    }
    else
    {
        if (FB.IsLoggedIn)
        {
            Debug.Log("logged in");
            AccessToken token = AccessToken.CurrentAccessToken;
            Credential credential = FacebookAuthProvider.GetCredential(token.TokenString);
            accessToken(credential);
        }

        else
            Debug.Log("not logged in");
    }
}

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

}


是的,这是标准测试屏幕。 您可以在Facebook开发人员页面上获取测试令牌(角色->测试用户->单击“编辑”按钮->获取该用户的访问令牌)。 每当您的应用程序连接到Facebook应用程序时,都会生成类似的令牌。 通常,这是一个短暂的令牌,大约2个小时,因此您无需保存它。

暂无
暂无

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

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