question

Evan Maxey avatar image
Evan Maxey asked

How to get display name using ID from entity key title_player_account provided in lobby invites

I have a listener for PlayFabMultiplayer.OnLobbyInviteReceived that correctly sees an invite from one player to another. The use case is to show the display name of the invitor to the person who received the invite. We're building in Unity.

The method catching the event receives entity information with invitor's title_player_account id. Here's the receiving method.

 public static void xyz_HandleReceivedLobbyInvite(
  PFEntityKey listeningEntityKey, 
  PFEntityKey invitorEntityKey, 
  string lobbyConnectionString )
  { 
      Debug.Log($
         "listeningEntityKey {listeningEntityKey.Id} {listeningEntityKey.Type}
           invitorEntityKey {invitorEntityKey.Id} {invitorEntityKey.Type} 
           with connection string {lobbyConnectionString}");
 }

I have validated the incoming values checking the information of the players involved in the invite and it is all correct... it is title info.

How do I get the invitor's display name using the title player account ID of the invitor?

We have azure functions with authentication to get to all the api's and I've experimented with pretty much every api out there and cannot find a working path to get the display name. This post is close to the same question. However I cannot find a way to make a get profile call return a result either from an Azure Function or from a client api call in unity. Here's Azure function code:

 PlayFab.ProfilesModels.GetEntityProfileRequest  profReq = new PlayFab.ProfilesModels.GetEntityProfileRequest();                
 PlayFab.ProfilesModels.EntityKey theKey = new PlayFab.ProfilesModels.EntityKey();
 theKey.Id = idForName;  //this is the invitor's title ID received from listener 
 theKey.Type = "title_player_account";
 profReq.Entity = theKey;    
 PlayFab.ProfilesModels.GetEntityProfileResponse resp = (await PlayFabProfilesAPI.GetProfileAsync(profReq)).Result;

"resp" always comes back null.

I've been scouring posts and api's for about 8 hours and cannot find an answer.

Very frustrating that there's not a straight forward way to get to a players title info, specifically display name, using the players title ID when that's what lobby seems to be based on. Pretty straight forward thing if you have the PlayfabID (master). Not so much if all you have is Title Player ID.

Please help! :)

Title Data
10 |1200

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

Neils Shi avatar image
Neils Shi answered

You can refer to my testing Azure Function code below. In addition, we recommend that you debug locally before deploying it to Azure, you can follow this documentation https://learn.microsoft.com/en-us/gaming/playfab/features/automation/cloudscript-af/local-debugging-for-cloudscript-using-azure-functions .

 public static class HttpTrigger1 
     {
         [FunctionName("HttpTrigger1")]
        public static async Task<dynamic> Run(
             [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
             ILogger log)
         {
             FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());
    
             var api = new PlayFabProfilesInstanceAPI(
                 new PlayFabApiSettings
                 {
                     TitleId = context.TitleAuthenticationContext.Id
                 },
                 new PlayFabAuthenticationContext
                 {
                     EntityToken = context.TitleAuthenticationContext.EntityToken
                 }
             );
    
             var apiResult = await api.GetProfileAsync(
                 new GetEntityProfileRequest
                 {
                     Entity = new PlayFab.ProfilesModels.EntityKey
                     {
                         Id = "A951DF5Cxxxxxxxxx",
                         Type = "title_player_account"
                     },
                 }
                 );
    
             return new { apiResult.Result.Profile.Lineage.MasterPlayerAccountId };
         
         }
     }
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.

Evan Maxey avatar image Evan Maxey commented ·

@Neils Shi Bingo! Setting the context information for the profiles api did the magic. Thanks again for your patient follow ups :)

0 Likes 0 ·
Neils Shi avatar image
Neils Shi answered

To clarify, the Display name in Entity data model is different from classic data model. If you configured Display name in Game Manager or via API UpdateUserTitleDisplayName, then you can't use API GetProfile (which retrieves the entity's profile) to get Display name. A work around solution is to use title player ID in API GetProfile to retrieve master player ID (PlayFab ID) first, then calling API GetPlayerProfile to retrieve player’s DisplayName.

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.

Evan Maxey avatar image Evan Maxey commented ·

@Neils Shi Did you have a chance to look at the post below?

0 Likes 0 ·
Evan Maxey avatar image
Evan Maxey answered

@Neils Shi In an azure function with SDK or in the unity SDK, what does the call look like to do "a work around solution is to use title player ID in API GetProfile"? I cannot find a way to get it to work. Very comfortable getting name from playfabid once that is known. Appreciate the help!

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.

Neils Shi avatar image Neils Shi commented ·

If you want to know how to use title player account id to retrieve master player account id via API GetProfile, you can refer to my Unity SDK example code:

 public void GetProfileTest()
     {
         PlayFabProfilesAPI.GetProfile(new PlayFab.ProfilesModels.GetEntityProfileRequest()
         {
             Entity = new PlayFab.ProfilesModels.EntityKey { Id = "F9AB6246xxxxxxxx", Type = "title_player_account" }
         },
    result => {
        Debug.Log("master player account id:"+result.Profile.Lineage.MasterPlayerAccountId);
    },
    error => {
        Debug.Log("retrieve master player account id fail");
        Debug.Log(error.GenerateErrorReport());
    });
     }
0 Likes 0 ·
Evan Maxey avatar image
Evan Maxey answered

@Neils Shi. Many thanks, on the road this week and next. Will try it when i get home.

10 |1200

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

Evan Maxey avatar image
Evan Maxey answered

@Neils Shi Hi Neils - Trying the code snippet... In order to get to the right permissions for profile request I'm calling to an azure function via PlayFabCloudScriptAPI.ExecuteFunction. Same pattern we successfully use for accessing privileged APIs. Here's the code I'm using based on your snippet in the Azure function, "cleanID" is the input title ID which I have verified gets to the function correctly:

 PlayFab.ProfilesModels.GetEntityProfileRequest profReq = new
    PlayFab.ProfilesModels.GetEntityProfileRequest()
       { Entity = new PlayFab.ProfilesModels.EntityKey 
          { Id = cleanID, Type = "title_player_account" } };
 PlayFab.ProfilesModels.GetEntityProfileResponse resp = 
      (await PlayFabProfilesAPI.GetProfileAsync(profReq)).Result;

The call fails with a generic failure, output caught on unity side is:

  • PlayFabError.GenerateErrorReport: Invocation of cloud script function PHAzureFunctionsII failed with HTTP status InternalServerError and response body

  • Error Message: Invocation of cloud script function PHAzureFunctionsII failed with HTTP status InternalServerError and response body

  • httpCode: 400

  • http Status: BadRequest

The Azure function runs normally if I simply echo the input ID in response, it fails when I try to make the call I listed above. Is there something mal-formed in my adoption of your example? Thoughts?

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.