question

choi dong geun avatar image
choi dong geun asked

DeveloperSecretKey must be set in your local or global settings to call this method

I keep having problems changing my cloudscript to azure.

I wrote the azure function and debug it, and it says, "Developer Secret Key must be set in your local or global settings to call this method."
Where can I find the document with this part?

10 |1200

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

Gosen Gao avatar image
Gosen Gao answered

For this issue, you may need to add Application settings in Azure function. For more info, you can refer to Where to set DeveloperSecretKey for Azure PlayFabServerAPI calls.

10 |1200

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

choi dong geun avatar image
choi dong geun answered
using System.Net.Security;
using System.Diagnostics;
using System;
using System.IO;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using PlayFab.ServerModels;
using PlayFab.Json;
using PlayFab.DataModels;
using PlayFab.Internal;
using PlayFab;
namespace Company.Function
{
    public static class UpdateSession
    {
        [FunctionName("UpdateSession")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());
            var request = new UpdateUserInternalDataRequest
            {
                PlayFabId = context.CallerEntityProfile.Lineage.MasterPlayerAccountId,
                Data = new Dictionary<string, string>()
                {
                    {"session", "abc"}
                }
            };
            var settings = new PlayFabApiSettings
            {
                TitleId = context.TitleAuthenticationContext.Id,
                DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY", EnvironmentVariableTarget.Process)
            };
            var authContext = new PlayFabAuthenticationContext
            {
                EntityToken = context.TitleAuthenticationContext.EntityToken
            };
            var serverApi = new PlayFabServerInstanceAPI(settings, authContext);
            var result = await serverApi.UpdateUserInternalDataAsync(request);
            return new Dictionary<string, string>()
            {
                {"test", "test"}
            };
        }
    }
}
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.