question

xnoendx avatar image
xnoendx asked

[Unity] Get Player Country

Hi,

I'm trying to get player location/country so I can display it in the Leaderboard.

The LeaderBoardEntry returns errors/nulls when asking for LeaderBoardEntry.Profile.Locations[0].CountryCode;

Is it possible to get the country from any other possible functions in Unity SDK?

Thanks in advance

Player DataLeaderboards and StatisticsAccount Management
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

·
brendan avatar image
brendan answered

Can you try updating to the latest SDK, released today? There was an issue with the previous SDK, in that it used an out-of-date version of the response data.

11 comments
10 |1200

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

xnoendx avatar image xnoendx commented ·

Hi Brendan,

Thanks for the answer, actually this was used with March's SDK. Can you please share a sample code? I will test and get back with the results

0 Likes 0 ·
brendan avatar image brendan ♦♦ xnoendx commented ·

Can you share the code snippet showing how you're querying for the leaderboard info?

0 Likes 0 ·
xnoendx avatar image xnoendx brendan ♦♦ commented ·
public void refreshLeaderboard() {


            PlayFab.ClientModels.GetLeaderboardRequest request = new PlayFab.ClientModels.GetLeaderboardRequest ();
            request.MaxResultsCount = 10;
            request.StatisticName = "MainLeaderBoard";
            request.ProfileConstraints.ShowLocations = true;


                PlayFabClientAPI.GetLeaderboard (request, GetLeaderboard, OnPlayFabError);
                

                
        }


        private void GetLeaderboard (PlayFab.ClientModels.GetLeaderboardResult result)
        {
            LeaderboardHighScores.Clear ();
           
            foreach (PlayFab.ClientModels.PlayerLeaderboardEntry entry in result.Leaderboard) {
                if (entry.DisplayName != null)
                {
                        LeaderboardHighScores.Add (entry.DisplayName, (uint)entry.StatValue); 

                        Debug.Log(entry.Profile.Locations.Count);
                    
                }
                    
                else
                    LeaderboardHighScores.Add (entry.PlayFabId, (uint)entry.StatValue); 
            }
            leaderboardLoaded = true;

            buildLB();
        }


0 Likes 0 ·
Show more comments
xnoendx avatar image xnoendx commented ·

Actually I'm getting nulls even if I call PlayerLeaderboardEntry.Profile.Locations.Count which should return the count.

My titleID is "B9DF"

Leaderboard ID is "MainLeaderBoard"

0 Likes 0 ·
brendan avatar image brendan ♦♦ xnoendx commented ·

I just tested your leaderboard in Postman, and I'm definitely seeing Location info for the players, so it sounds like the JSON serializer in your project is failing to get all the data. Are you using our default (SimpleJson) serializer, or another one? If it's the default, can you provide a repro project so that we can have the tools team look into this?

0 Likes 0 ·
xnoendx avatar image xnoendx brendan ♦♦ commented ·

I created a total new project just to test this function, still I'm getting the same error.

I'm not changing the JSON serializer so I'm assuming that I'm using SimpleJSON.

https://ufile.io/a833a

0 Likes 0 ·
Show more comments
bigdaddy avatar image bigdaddy commented ·

Hi. I also encounter the same problem. Do not know if you have solved this problem yet

0 Likes 0 ·
Andy avatar image Andy ♦♦ bigdaddy commented ·

You can go to Client Profile Options under Settings and choose what parts of a player's profile are available to the client, including location.

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.