question

Eduardo Philipe Viana de Lima avatar image
Eduardo Philipe Viana de Lima asked

I am having trouble receiving statistics from another player

I am trying to make a search engine of other players and receive the statistics and profile information But I keep getting null results in the cloud script. I'm using the DisplayName as a reference to find the player, also tried with playfabID but without success.

 public class OtherPlayerData
 {
     public string playerId;
     public string displayName;
     public Dictionary<string, object> Profile;
     public Dictionary<string, int> Statistics;
 }
    
 public void GetOtherPlayerDataByDisplayName(string displayName)
 {
     PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest()
     {
         FunctionName = "getOtherPlayerDataByDisplayName",
         FunctionParameter = new { displayName },
         GeneratePlayStreamEvent = true,
            
     }, OnGetOtherPlayerDataSuccess, OnGetOtherPlayerDataError);
 }
    
 private void OnGetOtherPlayerDataSuccess(ExecuteCloudScriptResult result)
 {
        
     if (result.FunctionResult == null)
     {
         Debug.Log("Resultado vazio ou nulo");
         return;
     }
    
     var data = JsonUtility.FromJson<OtherPlayerData>(result.FunctionResult.ToString());
     Debug.Log("Nome do jogador desejado: " + data.displayName);
     foreach (var stat in data.Statistics)
     {
         Debug.Log($"{stat.Key}: {stat.Value}");
     }
 }
    
 private void OnGetOtherPlayerDataError(PlayFabError error)
 {
     Debug.LogError(error.GenerateErrorReport());
 }
 public void SearchOtherPlayerData()
 {
     string DisplayName = nameSerach;
     GetOtherPlayerDataByDisplayName(DisplayName);
 }

Acima é a função que estou utilizando no Client.

 handlers.getOtherPlayerDataByDisplayName = function (args, context) {
     var displayName = args.displayName;
        
     var playerProfiles = server.GetPlayerProfiles({
         Profiles: [{ DisplayName: displayName }],
         ProfileConstraints: {
             ShowDisplayName: true,
             ShowStatistics: true,
         }
     });
        
     if (!playerProfiles || playerProfiles.length === 0) {
         return { error: "Jogador não encontrado" };
     }
        
     var playerProfile = playerProfiles[0];
        
     return {
         playerId: playerProfile.PlayerId,
         displayName: playerProfile.DisplayName,
         profile: playerProfile.Profile,
         statistics: playerProfile.Statistics
     };
 };

This is the Revisions on the cloudScript I'm using to send the data. If someone could kindly give me a light.

CloudScriptLeaderboards and Statistics
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

·
Simon Cui avatar image
Simon Cui answered

Hello, there is no server.GetPlayerProfiles API, do you mean this API Account Management - Get Player Profile - REST API (PlayFab Server) | Microsoft Learn? Besides, we recommend using client API Account Management - Get Account Info - REST API (PlayFab Client) | Microsoft Learn to search a player with TitleDisplayName. Then you can use the PlayFabId which returned from GetAccountInfoResult to get a player profile with Account Management - Get Player Profile - REST API (PlayFab Client) | Microsoft Learn. Furthermore, if you want to show statistics to other players, you can navigate to [Game Manager]-> [Your Title]-> [Titile settings] -> [Client Profile Options] to allow client access to “Statistics”.

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.