Update a player from anonymous to a Unity Player Account

Hi

I want to do an update a player from anonymous to a Unity Player Account, my code is this:

public async void SignInAnonymous()
{
AuthenticationService.Instance.ClearSessionToken();
await SignInAnonymouslyAsync();
}
async Task SignInAnonymouslyAsync()
{
try
{
await AuthenticationService.Instance.SignInAnonymouslyAsync();
Debug.Log(“Sign in anonymously succeeded!”);
// Shows how to get the playerID
Debug.Log($“PlayerID: {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);
}
}

public async void UpdateFromAnonymousToUnityPlayerAccount()
{
await PlayerAccountService.Instance.StartSignInAsync();
await LinkWithUnityAsync(PlayerAccountService.Instance.AccessToken);
}
async Task LinkWithUnityAsync(string accessToken)
{
try
{
await AuthenticationService.Instance.LinkWithUnityAsync(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);
}
}

But I get this error:

[Authentication]: Request failed: 400, {“title”:“INVALID_PARAMETERS”,“detail”:“external token not provided”,“details”:[ ],“status”:400}, request-id: 63bf303f-c23e-4bc4-a3c6-a467b111cbf8
UnityEngine.Logger:Log (string,object)
Unity.Services.Authentication.Logger:Log (object) (at Library/PackageCache/com.unity.services.authentication@3.0.0/Runtime/Utilities/Logger.cs:16)
Unity.Services.Authentication.AuthenticationExceptionHandler:ConvertException (Unity.Services.Authentication.WebRequestException) (at Library/PackageCache/com.unity.services.authentication@3.0.0/Runtime/Exceptions/AuthenticationExceptionHandler.cs:104)
Unity.Services.Authentication.AuthenticationServiceInternal/d__153:MoveNext () (at Library/PackageCache/com.unity.services.authentication@3.0.0/Runtime/AuthenticationServiceInternal.cs:825)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder1<Unity.Services.Authentication.LinkResponse>:SetException (System.Exception) Unity.Services.Authentication.WebRequest/<SendAsync>d__151<Unity.Services.Authentication.LinkResponse>:MoveNext () (at Library/PackageCache/com.unity.services.authentication@3.0.0/Runtime/Network/WebRequest.cs:63)
System.Threading.Tasks.TaskCompletionSource1<string>:SetException (System.Exception) Unity.Services.Authentication.WebRequest:RequestCompleted (System.Threading.Tasks.TaskCompletionSource1,long,bool,bool,string,string,System.Collections.Generic.IDictionary`2<string, string>) (at Library/PackageCache/com.unity.services.authentication@3.0.0/Runtime/Network/WebRequest.cs:193)
Unity.Services.Authentication.WebRequest/<>c__DisplayClass16_1:b__0 (UnityEngine.AsyncOperation) (at Library/PackageCache/com.unity.services.authentication@3.0.0/Runtime/Network/WebRequest.cs:76)
UnityEngine.AsyncOperation:InvokeCompletionEvent ()

A bit old but I have the same problem.

Did you solve this problem?

Also, why do you include AuthenticationService.Instance.ClearSessionToken(); in the beginning?