question

Stefan Tanasa avatar image
Stefan Tanasa asked

How to delete a master account in playfab

Hello everyone.

I'm trying to implement just a simple function that deletes the master player in playfab.
The problem that I am facing at the moment is that whenever I run this method in Unity, the following message appears (and the function is not executed properly):

Opps Something went wrong: /CloudScript/ExecuteFunction: Cloud script function MainFunction returned value that was too large


This is the code that I'm using for calling the function

PlayFabCloudScriptAPI.ExecuteFunction(new ExecuteFunctionRequest()
            {
                Entity = new PlayFab.CloudScriptModels.EntityKey()
                {
                    Id = PlayFabSettings.staticPlayer.EntityId, //Get this from when you logged in,
                    Type = PlayFabSettings.staticPlayer.EntityType, //Get this from when you logged in
                },
                FunctionName = "MainFunction", //This should be the name of your Azure Function that you created.
                FunctionParameter = new
                {
                    MasterID = localPlayer_PlayfabID
                }, //This is the data that you would want to pass into your function.
                GeneratePlayStreamEvent = false //Set this to true if you would like this call to show up in PlayStream
            }, (ExecuteFunctionResult result) =>
            {
                if (result.FunctionResultTooLarge ?? false)
                {
                    Debug.Log("This can happen if you exceed the limit that can be returned from an Azure Function, See PlayFab Limits Page for details.");
                    return;
                }
                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()}");
            });

And this is the Azure function:

[FunctionName("MainFunction")]
        public static async Task<OkResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", "delete", Route = null)] HttpRequest req,
            ILogger log)
        {


            var request = new DeleteMasterPlayerAccountRequest()
            {
                PlayFabId = req.Query["MasterID"]
            };


            var taskRequest = await PlayFabAdminAPI.DeleteMasterPlayerAccountAsync(request, null, null);
            var stringResult = taskRequest.Result.ToString();
            string responseMessage = string.IsNullOrEmpty(stringResult)
                ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, user. This HTTP triggered function executed successfully.";


            return new OkResult();
        }

I've been trying to find a reason as to why Unity says that the returned value was too large. Even when I'm putting a simple method such as a HelloWorld method, it still says the same thing.

unity3d
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

·
Gosen Gao avatar image
Gosen Gao answered

For this error, you can refer to https://community.playfab.com/questions/60094/hi-im-getting-this-error-opps-something-went-wrong.html

Also, there are some issue with the Azure Function you are using, “req.Query["MasterID"]” cannot get the value you passed through Function Parameter. And, to use PlayFab Admin API, you need to set the TitleId and DeveloperSecretKey first.

Here is an example for your reference. For more info, please refer to Quickstart: Writing a PlayFab CloudScript using Azure Functions.

[FunctionName("HttpTrigger1")]
public static async Task<PlayFab.PlayFabResult<DeleteMasterPlayerAccountResult>> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post",Route = null)] HttpRequest req, ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");
    FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());
    var args = context.FunctionArgument;
    string playFabId = args["MasterID"];
    log.LogInformation(playFabId);
    var apiSettings = new PlayFabApiSettings{
        TitleId = Environment.GetEnvironmentVariable("PLAYFAB_TITLE_ID",EnvironmentVariableTarget.Process),
        DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY",EnvironmentVariableTarget.Process)
    };
    var adminApi = new PlayFabAdminInstanceAPI(apiSettings);
    var request = new DeleteMasterPlayerAccountRequest(){
        PlayFabId = playFabId
    };
    var ret = await adminApi.DeleteMasterPlayerAccountAsync(request);
    return ret;
}
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.