Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by Arnau Castillo · Feb 23 at 11:28 AM · CloudScriptapisLeaderboards and Statistics

Update Statistic: invocation of cloud script function failed

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

Comment

People who like this

0 Show 1
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Arnau Castillo · Feb 23 at 11:37 AM 0
Share

The error is here:

And this is the line 260 of the second .cs

error1playfab.png (35.6 kB)
error2playfab.png (59.9 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Gosen Gao · Feb 24 at 09:24 AM

You can follow Tutorial: Debugging CloudScript using Azure Functions with the Azure portal to check the streaming logs for troubleshooting. If there are no logs in the logstream, there may be something incorrect when registering the function to PlayFab. As the document of Azure Function mentioned, "Functions lets you use keys to make it harder to access your HTTP function endpoints during development. Unless the HTTP access level on an HTTP triggered function is set to anonymous, requests must include an API access key in the request." Since you are using Function level, please check your URL to see if it has the API access key.

Comment

People who like this

0 Show 1 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Arnau Castillo · Feb 26 at 02:20 PM 0
Share

Thanks, I finally found the answer here.
https://community.playfab.com/questions/38397/where-to-set-developersecretkey-for-azure-playfabs.html

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    11 People are following this question.

    avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

    Related Questions

    best practice for saving statistics for leaderboards 1 Answer

    Can Cloud Code Access the Admin API 1 Answer

    Azure Function PLAYFAB_DEV_SECRET_KEY simple question 1 Answer

    CustomTags conditions,Custom tag in conditions 2 Answers

    Advantages of CloudScript over Calling JavaScript from Node.js 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges