There is the code I load data after await AuthenticationService.Instance.SignInWithFacebookAsync(aToken.TokenString);
But data is not loaded from account linked with current facebook account.
async void Awake()
{
await UnityServices.InitializeAsync();
await AuthenticationService.Instance.SignInAnonymouslyAsync();
// InitializePlayGamesLogin();
if (!FB.IsInitialized)
{
// Initialize the Facebook SDK
FB.Init(InitCallback, OnHideUnity);
}
else
{
// Already initialized, signal an app activation App Event
FB.ActivateApp();
//FacebookLogin();
GetProfilePicture();
// AuthenticationService.Instance.
var aToken = AccessToken.CurrentAccessToken;
Debug.LogError(aToken);
FacebookLogin();
}
}
#region Facebook
private void InitCallback()
{
if (FB.IsInitialized)
{
// Signal an app activation App Event
FB.ActivateApp();
//FacebookLogin();
// Continue with Facebook SDK
// ...
if (FB.IsLoggedIn)
GetProfilePicture();
}
else
{
Debug.Log("Failed to Initialize the Facebook SDK");
}
}
private void OnHideUnity(bool isGameShown)
{
Time.timeScale = isGameShown ? 1 : 0;
}
public void FacebookLogin()
{
var perms = new List<string>() { "public_profile", "gaming_profile", "gaming_user_picture" };
FB.LogInWithReadPermissions(perms, AuthCallback);
}
private async void AuthCallback(ILoginResult result)
{
if (FB.IsLoggedIn)
{
var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
Debug.Log(aToken.UserId);
GetProfilePicture();
await AuthenticationService.Instance.SignInWithFacebookAsync(aToken.TokenString);
GameLogic.Instanse.LoadData();
//AuthenticationService.Instance.LinkWithFacebookAsync();
}
else
{
Debug.Log("User cancelled login");
}
}
async Task LinkWithFacebookAsync(string accessToken)
{
try
{
await AuthenticationService.Instance.LinkWithFacebookAsync(accessToken);
Debug.Log("Link is successful.");
}
catch (AuthenticationException ex) when (ex.ErrorCode == AuthenticationErrorCodes.AccountAlreadyLinked)
{
// Prompt the player with an error message.
Debug.LogError("This user is already linked with another account. Log in instead.");
}
catch (AuthenticationException ex)
{
// Compare error code to AuthenticationErrorCodes
// Notify the player with the proper error message
Debug.LogException(ex);
}
catch (RequestFailedException ex)
{
// Compare error code to CommonErrorCodes
// Notify the player with the proper error message
Debug.LogException(ex);
}
}