When I pass the facebook access token to Unity Authentication, by calling AuthenticationService.Instance.SignInWithFacebookAsync(accessToken), I got errors from each catch :
-
[Authentication]: Request failed: 401, {“title”:“PERMISSION_DENIED”,“detail”:“unable to validate token”,“details”:,“status”:401}
-
WebRequestException: {“title”:“PERMISSION_DENIED”,“detail”:“unable to validate token”,“details”:,“status”:401}
Below is my code, AuthCallback will be called after user logged in through facebook.
private async void AuthCallback(ILoginResult result)
{
if (FB.IsLoggedIn)
{
// AccessToken class will have session details
var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
// Print current access token's User ID
Debug.Log("UserId : " + aToken.UserId);
// Print current access token's granted permissions
foreach (string perm in aToken.Permissions)
{
Debug.Log(perm);
}
await SignInWithFacebookAsync(aToken.TokenString);
}
else
{
Debug.Log("User cancelled login");
}
}
private async Task SignInWithFacebookAsync(string accessToken)
{
try
{
await AuthenticationService.Instance.SignInWithFacebookAsync(accessToken);
Debug.Log("SignIn is successful : " + AuthenticationService.Instance.PlayerId);
}
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);
}
}