question

Kim Strasser avatar image
Kim Strasser asked

How can I use SetProfileLanguage in Azure Functions?

I want to set the players language in my Azure function but I don't know how to do that.

How can I use ProfilesModels and SetProfileLanguage in my Azure function to set or update the players language? What is request.Entity?

[FunctionName("ChangePlayersLanguage")]
public static async Task<dynamic> MakeApiCall(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage req, ILogger log)
{	
    var context = await FunctionContext<dynamic>.Create(req);
    var args = context.FunctionArgument;
    var language = args["Language"];
           
    var request = new PlayFab.ProfilesModels.SetProfileLanguageRequest();
    request.ExpectedVersion = 0;
    request.Entity = ?
    request.Language = language;

    var result = await ?

}
CloudScript
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

·
Seth Du avatar image
Seth Du answered

As you have asked the Azure Function usage question before and I believe Sarah has provided a detailed code snippet for you recently. All the PlayFab API usage is very similar. Since I prefer using instance API, I will offer my solution of using Instance API.

>>What is request.Entity?

May I ask is the question about how to get the entity of the caller in the script? Otherwise, does it mean you are not sure what entity should be used in the request?

Caller information can be retrieved via context, you may create a test function to output context for reference.

var context = await FunctionContext<dynamic>.Create(req);

Please understand that repetitive general usage questions are not recommended in the forum as it is fragmented, which is also not friendly for the community developers to locate a valuable answer. Your question is confusing, and I am not sure the question is based on the usage of Azure Function usage or PlayFab API usage. Either way, I will recommend you to walk through the both documentation and implement official samples before you starting working on your own project. If it is about PlayFab API usage, I suggest you to use Postman to test the corresponding API, and it can help you learn each property in the request.

If you have any question on general use of Azure function, please leave the comment in this thread. Hopefully, you can add this thread webpage to your browser favorites for later reference.

public static class ProfileTest
    {
        [FunctionName("ProfileTest")]
        public static async Task<dynamic> MakeApiCall(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage req, ILogger log)
        {
            /* Create the function execution's context through the request */
            var context = await FunctionContext<dynamic>.Create(req);
            var args = context.FunctionArgument;
 
 
            var desiredLanguage = args["Language"];
 
            /* Create the request object through the SDK models */
            var request = new SetProfileLanguageRequest();
            request.Entity = context.CallerEntityProfile.Entity;
            request.Language = desiredLanguage;


            /* Use the ApiSettings and AuthenticationContext provided to the function as context for making API calls. */
            var profileAPI = new PlayFabProfilesInstanceAPI(context.ApiSettings, context.AuthenticationContext);
         
            /* The PlayFabServerAPI SDK methods provide means of making HTTP request to the PlayFab Main Server without any 
             * extra code needed to issue the HTTP requests. */
            return await profileAPI.SetProfileLanguageAsync(request);
        }
    }
1 comment
10 |1200

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

Kim Strasser avatar image Kim Strasser commented ·

>>What is request.Entity?

May I ask is the question about how to get the entity of the caller in the script? Otherwise, does it mean you are not sure what entity should be used in the request?

Caller information can be retrieved via context, you may create a test function to output context for reference.

I didn't know that I could use context.CallerEntityProfile.Entity in the request. I wasn't sure if it is the same Entity that I need to use in the request.

0 Likes 0 ·

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.