question

tyronecordes2 avatar image
tyronecordes2 asked

Get Title Entity token in Azure Functions,Get entity title with GetEntityTokenRequest with Azure Functions

Hello, i have been trying to get the title entity however every time it returns:

Failed to get entity token: This API method does not allow anonymous callers.

what am i doing wrong?

Code(Not cleaned, was trying to figure out how to do this):

 public static class EconomyApi
     {
         private static readonly string PlayFabTitleId = Environment.GetEnvironmentVariable("PlayFabTitleId");
         private static readonly string PlayFabDeveloperSecretKey = Environment.GetEnvironmentVariable("PlayFabDeveloperSecretKey");
     public static async Task<PlayFabEconomyInstanceAPI> InstanceAsync(ILogger log)
     {
         PlayFabSettings.staticSettings.TitleId = PlayFabTitleId;
         PlayFabSettings.staticSettings.DeveloperSecretKey = PlayFabDeveloperSecretKey;
         // var settings = new PlayFabApiSettings
         // {
         //     TitleId = PlayFabTitleId,
         //     DeveloperSecretKey = PlayFabDeveloperSecretKey // Note: This might not be needed for obtaining an Entity Token and should be used cautiously.
         // };
    
         var entityToken = await GetTitleEntityTokenAsync(log);
         var authContext = new PlayFabAuthenticationContext
         {
             EntityToken = entityToken
         };
            
            
    
         return new PlayFabEconomyInstanceAPI(PlayFabSettings.staticSettings, authContext);
     }
    
     public static async Task<string> GetTitleEntityTokenAsync(ILogger log)
     {
         PlayFabSettings.staticSettings.TitleId = PlayFabTitleId;
         PlayFabSettings.staticSettings.DeveloperSecretKey = PlayFabDeveloperSecretKey;
    
         var request = new GetEntityTokenRequest(){
    
         };
         var response = await PlayFabAuthenticationAPI.GetEntityTokenAsync(request);
    
         if (response.Error != null)
         {
             log.LogError($"Failed to get entity token: {response.Error.GenerateErrorReport()}");
             return null; // Consider how to handle errors appropriately in your context.
         }
    
         return response.Result.EntityToken;
     }
    
     }

,Hello, i have been trying to get the title entity however every time it returns:

Failed to get entity token: This API method does not allow anonymous callers.

what am i doing wrong?

Code(Not cleaned, was trying to figure out how to do this):

 public static class EconomyApi
     {
         private static readonly string PlayFabTitleId = Environment.GetEnvironmentVariable("PlayFabTitleId");
         private static readonly string PlayFabDeveloperSecretKey = Environment.GetEnvironmentVariable("PlayFabDeveloperSecretKey");
     public static async Task<PlayFabEconomyInstanceAPI> InstanceAsync(ILogger log)
     {
         PlayFabSettings.staticSettings.TitleId = PlayFabTitleId;
         PlayFabSettings.staticSettings.DeveloperSecretKey = PlayFabDeveloperSecretKey;
         // var settings = new PlayFabApiSettings
         // {
         //     TitleId = PlayFabTitleId,
         //     DeveloperSecretKey = PlayFabDeveloperSecretKey // Note: This might not be needed for obtaining an Entity Token and should be used cautiously.
         // };
    
         var entityToken = await GetTitleEntityTokenAsync(log);
         var authContext = new PlayFabAuthenticationContext
         {
             EntityToken = entityToken
         };
            
            
    
         return new PlayFabEconomyInstanceAPI(PlayFabSettings.staticSettings, authContext);
     }
    
     public static async Task<string> GetTitleEntityTokenAsync(ILogger log)
     {
         PlayFabSettings.staticSettings.TitleId = PlayFabTitleId;
         PlayFabSettings.staticSettings.DeveloperSecretKey = PlayFabDeveloperSecretKey;
    
         var request = new GetEntityTokenRequest(){
    
         };
         var response = await PlayFabAuthenticationAPI.GetEntityTokenAsync(request);
    
         if (response.Error != null)
         {
             log.LogError($"Failed to get entity token: {response.Error.GenerateErrorReport()}");
             return null; // Consider how to handle errors appropriately in your context.
         }
    
         return response.Result.EntityToken;
     }
    
     }
entitiesAuthentication
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Xiao Zha avatar image
Xiao Zha answered

No matter the method for executing Azure Function the Title Authentication context(which contain the Title Entity Token) is always provided. So, you don’t have to call GetEntityToken manually to get Title Entity Token in Azure Function. Please refer to PlayFab CloudScript using Azure Functions Context Models - PlayFab | Microsoft Learn.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.