Hi, I am trying to update an statistic with an Azure Function (which I think it is fine). I don't manage to solve this problem.
This is the azure function, which I can publish without a problem. If I publish another function that only returns the name and time it works fine. The problem is with the request to update the statistic.
Azure function:
namespace FuncionRankingPrueba1 { public static class RankingPrueba { [FunctionName("UpdateRanking")] public static async Task<dynamic> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { string name; string time; string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); name = data?.FunctionArgument?.name; time = data?.FunctionArgument?.time; int timeint= int.Parse(time); var request = new UpdatePlayerStatisticsRequest { PlayFabId = data.CallerEntityProfile.Lineage.MasterPlayerAccountId, Statistics = new List<StatisticUpdate> { new StatisticUpdate { StatisticName = name, Value = timeint } } }; var apiSettings = new PlayFabApiSettings { TitleId = data.TitleAuthenticationContext.Id, DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY", EnvironmentVariableTarget.Process), }; var serverApi = new PlayFabServerInstanceAPI(apiSettings); return await serverApi.UpdatePlayerStatisticsAsync(request); } } }
This is the call from my project, where Prueba3Arnau is the name of the function in Playfab, Level1Times is the statistic name I want to update and time is the integer to pass:
public void UpdateLeaderBoard() { Debug.Log("UpdateLead"); PlayFabCloudScriptAPI.ExecuteFunction(new ExecuteFunctionRequest() { Entity = new PlayFab.CloudScriptModels.EntityKey() { Id = PlayFabSettings.staticPlayer.EntityId, Type = PlayFabSettings.staticPlayer.EntityType, }, FunctionName = "Prueba3Arnau", FunctionParameter = new {name= "Level1Times", time="21"}, GeneratePlayStreamEvent = false }, (ExecuteFunctionResult result) => { Debug.Log($"The {result.FunctionName} function took {result.ExecutionTimeMilliseconds} to complete"); Debug.Log($"Result: {result.FunctionResult.ToString()}"); }, (PlayFabError error) => { Debug.Log($"Opps Something went wrong: {error.GenerateErrorReport()}"); }); }
This is the error
If I go to the second .cs (Assets/PlayFabSDK/Shared...), line 260, this is where it goes:
I don't know if it has something to do with the secret key, a permit that I have to grant or what.
Thanks