question

robertgrospitch avatar image
robertgrospitch asked

Getting Display Name From Cloudscript

Hello All,

I was wondering If it is possible to get just the Display Name from a user account in a cloudscript. I am currently working on a project where I need to make an api call that includes the users display name. However, everything I am trying is not giving just the display name.

For example: in my azure function I can say:

    public static class PlayfabRequest
    {
        [FunctionName("PlayfabRequest")]
        public static async Task<dynamic> Run(
            [HttpTrigger(AuthorizationLevel.Function, "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 GetPlayerData = new GetPlayerProfileRequest
            {
                PlayFabId = context.CallerEntityProfile.Lineage.MasterPlayerAccountId,
            };
            
            var serverApi = new PlayFabServerInstanceAPI(context.ApiSettings, context.AuthenticationContext);
            
            return await serverApi.GetPlayerProfileAsync(GetPlayerData);
            
        }

    }

I am returning:

Result: {"result":{"playerProfile":{"adCampaignAttributions":null,"avatarUrl":null,"bannedUntil":null,"contactEmailAddresses":null,"created":null,"displayName":"g.gji.wam","experimentVariants":null,"lastLogin":null,"linkedAccounts":null,"locations":null,"memberships":null,"origination":null,"playerId":"EAD936D301EC0DC","publisherId":"3F50A3858CE1D5DA","pushNotificationRegistrations":null,"statistics":null,"tags":null,"titleId":"D1EA1","totalValueToDateInUSD":null,"valuesToDate":null}},"customData":null,"error":null}

Which is great because I know its getting the info, however, I want to save "DisplayName" information into a variable on the function to use.

Any thoughts?

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.

robertgrospitch avatar image robertgrospitch commented ·

Quick Addition: Why can I not use var displayName = context.CallerEntityProfile.DisplayName;

It seems that it gives me an error when I call this. But when I call context.CallerEntityProfie.Lineage, everything works just fine.

0 Likes 0 ·

1 Answer

·
Made Wang avatar image
Made Wang answered

In fact, you have already got the DisplayName. You can refer to the following code.

var playerProfile = await serverApi.GetPlayerProfileAsync(GetPlayerData);
var displayName = playerProfile.Result.PlayerProfile.DisplayName;

I guess you used PlayFabFunctionContexts, and you can check what the context contains in that tool class.

If you want to know what content is contained in the entity file obtained through the ExecuteFunction API, you can refer to PlayFab CloudScript using Azure Functions Context Models - PlayFab | Microsoft Docs.

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.