I know this is a silly question but how can I easily save the user access token after a user logs in?
Here is a part of my code that is triggered by a button:
public class FacebookLogin : MonoBehaviour {
void Awake()
{
if (!FB.IsInitialized)
{
FB.Init(InitCallback, OnHideUnity);
}
else
{
FB.ActivateApp();
}
}
private void InitCallback()
{
if (FB.IsInitialized)
{
FB.ActivateApp();
}
else
{
Debug.Log("Failed to Initialize the Facebook SDK");
}
}
private void OnHideUnity(bool isGameShown)
{
if (!isGameShown)
{
Time.timeScale = 0;
}
else
{
Time.timeScale = 1;
}
}
public void FBLogin()
{
List<string> perms = new List<string>() { "public_profile", "email", "user_friends" };
FB.LogInWithReadPermissions(perms, AuthCallback);
}
private void AuthCallback(ILoginResult result)
{
if (FB.IsLoggedIn)
{
var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
FB.API("/me?fields=first_name", HttpMethod.GET, getName);
FB.API("/me/picture?type=square&height=128&width=128", HttpMethod.GET, getProfilePic);
SceneManager.LoadScene("Main_Menu");
}
else
{
Debug.Log("User cancelled login");
}
}
private void getName(IResult result)
{
LocalDataBase.Name = result.ResultDictionary["first_name"].ToString();
}
private void getProfilePic(IGraphResult result)
{
LocalDataBase.profilePicture = result;
}
}
Thank you in advance for all your answers.