question

Rizwan Babar avatar image
Rizwan Babar asked

Get Player Country

How can I get country of player entries in leaderboard to display their country flags?

I tried this:

but it returns Null in debug log. Is there something I am missing?

Leaderboards and Statisticslimits
c1.png (13.0 KiB)
10 |1200

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

Gosen Gao avatar image
Gosen Gao answered

There is a parameter name ProfileConstraints in GetLeaderboard’s request body. This parameter decides what player profile will return. If you want to get player’s locations, please add ProfileConstraints in your request and set ShowLocations to true.

However, the player's locations are not allowed to be read by the client by default. So before you call again, please navigate to [Title Setting]->[Client Profile Options]->[ALLOW CLIENT ACCESS TO PROFILE PROPERTIES]. And make sure the option “Locations” is selected.

5 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.

Rizwan Babar avatar image Rizwan Babar commented ·

Do I have to use Profile Constraints parameter in leaderboard? I tried using it in leaderboard yesterday but it didn't work so I tried using it PlayFabClientAPI.GetPlayerProfile request and it worked. But doing another api call increases time for leaderboard loading. So can I get it directly from leaderboard player entry?

0 Likes 0 ·
Rizwan Babar avatar image Rizwan Babar Rizwan Babar commented ·

if do something like Debug.Log(player.Profile.Locations.Count) (player is PlayerLeaderboardEntry), it returns null. Permissions are allowed in my PlayFab dashboard too.

0 Likes 0 ·
Gosen Gao avatar image Gosen Gao Rizwan Babar commented ·

Code below returns the right count of Locations.

PlayFabClientAPI.GetLeaderboard(new GetLeaderboardRequest { 
    StatisticName = "StatisticName",
    MaxResultsCount = 20,
    ProfileConstraints = new PlayerProfileViewConstraints
    {
        ShowLocations = true
    }
}, result => {
    foreach(PlayerLeaderboardEntry player in result.Leaderboard)
    {
        Debug.Log(player.Profile.Locations.Count);
    }
}, error => { 
    Debug.LogError(error.GenerateErrorReport());
});

Would you please try this code again?

0 Likes 0 ·
Show more comments
jjabrahans avatar image
jjabrahans answered

It's not working here. Returning me a Null Reference.

10 |1200

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

brickmancica avatar image
brickmancica answered

For me return value 1 for each item...?

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.