question

daniel.berkbox@gmail.com avatar image
daniel.berkbox@gmail.com asked

Calling DeleteMasterPlayerAccount from server script (legacy)

Hi,

Would it be possible to call Calling DeleteMasterPlayerAccount from legacy server script maybe using http object or the only way is through an Azure function? Is there any implementation example? I'm a little lost with this. Thank you!

10 |1200

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

Made Wang avatar image
Made Wang answered

1. I don't think the 2016 version can do it, you can provide a specific version number and I will do some tests.

2. It is recommended that you contact Apple to understand their specific requirements. You can refer to PlayFab CloudScript using Azure Functions Quickstart Guide - PlayFab | Microsoft Docs to integrate Azure Function, and if you encounter some problems in use, feel free to post a new thread.

3. Yes, you need a paid subscription, you can consult Azure for subscription information to determine which subscription is more suitable for you. During development you can test locally, which is free, refer to Local debugging for Cloudscript using Azure Functions - PlayFab | Microsoft Docs.

4. It is recommended to use the latest version of the SDK, you can refer to the code below to call the above Azure Function in Unity.

using PlayFab;
using PlayFab.CloudScriptModels;

public void DeleteMasterPlayerAccount(string playfabId)
{
    PlayFabCloudScriptAPI.ExecuteFunction(new ExecuteFunctionRequest
    {
        FunctionName = "Test",
        FunctionParameter = new Dictionary<string, string>()
        {
            {"playfabId",playfabId }
        },
        GeneratePlayStreamEvent = true
    },
    (result) =>
    {
        Debug.Log("execute success");
    },
    (error) =>
    {
        Debug.LogError(error.GenerateErrorReport());
    });
}

5. You can also refer to the code below to call API via Http in Cloud Script(Legacy).

handlers.HttpRequest=function(args,context){
    var headers = {
        "X-SecretKey": " "
    };
    var body = {
        PlayFabId: args.playfabId
    };
    //DeleteMatserPlayerAccount
    var url = "https://[titleId].playfabapi.com/Admin/DeleteMasterPlayerAccount";
    var content = JSON.stringify(body);
    var httpMethod = "post";
    var contentType = "application/json";
    var response = http.request(url, httpMethod, content, contentType, headers);
    return { responseContent: response };
}
10 |1200

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

Made Wang avatar image
Made Wang answered

Does server script(legacy) mean Cloud Script(Legacy)?

In Cloud Script (Legacy), you can use http to call the admin API, but we do not recommend this, we recommend using Azure Function, refer to the code below.

using System;
using System.IO;
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;
using PlayFab.Samples;
using PlayFab.AdminModels;


namespace Company.Function
{
    public static class Test
    {
        [FunctionName("Test")]
        public static async Task<dynamic> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());
            dynamic args = context.FunctionArgument;
            var request=new DeleteMasterPlayerAccountRequest{
                PlayFabId=args["playfabId"]
            };
            var setting=new PlayFabApiSettings{
                TitleId=context.TitleAuthenticationContext.Id,
                DeveloperSecretKey=" "
            };
            var adminApi=new PlayFabAdminInstanceAPI(setting);
            await adminApi.DeleteMasterPlayerAccountAsync(request);
            return null;
        }
    }
}
10 |1200

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

daniel.berkbox@gmail.com avatar image
daniel.berkbox@gmail.com answered

Hi Made Wang and all,

Thanks a lot for the help, I appreciate it. Yes, I mean Cloud Script(Legacy).

But I have some concerns:

1. My app uses an old version of the sdk (from 2016) and I don't know if it would support calls to azure functions.

2. Apple deletion account requirement forces us to update the app by June 30th (it's not clear to me that updating is mandatory or if it's just for new apps, what do you guys think?) and I don't know if I have time to learn how to implement and integrate Azure Functions to that date.

3.I have to subscribe to an Azure paid subscription right?

forgive me if i'm abusing but could you give me an example of how to call azure function from c# (unity client) and what version of the sdk do I need?

Would it be possible to also give us an example of how to call the DeleteMasterPlayerAccount api from the legacy cloud script in case I don't have time to use Azure?

Thank you again!

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.