question

Talha avatar image
Talha asked

How to get Locations in Cloudscript of a certain Player?

Hi, This is how I'm doing it. Please let me know What's wrong.

I can successfully retrieve DisplayName, But Locations, Cant. Please Help!

  var XPlayerRequest = {
        "PlayFabId": UpperPlayFabID,
        "InfoRequestParameters": {
            "GetUserAccountInfo": true,
            "GetUserInventory": false,
            "GetUserVirtualCurrency": false,
            "GetUserData": true,
            "GetUserReadOnlyData": true,
            "GetCharacterInventories": false,
            "GetCharacterList": false,
            "GetTitleData": false,
            "GetPlayerStatistics": true,
            "GetPlayerProfile"  : true
        }
    };


 var XPlayerInfo = server.GetPlayerCombinedInfo(XPlayerRequest); 
 var XPlayerLocations = XPlayerInfo.InfoResultPayload.PlayerProfile.Locations;
 var XPlayerCity= XPlayerLocations[0].City;
 var XPlayerCountry= XPlayerLocations[0].CountryCode;
 var XPlayerName= XPlayerInfo.InfoResultPayload.PlayerProfile.DisplayName;

CloudScript
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

·
Sarah Zhang avatar image
Sarah Zhang answered

You haven’t set the ProfileConstraints’s property ShowLocations, it defaults to false. You can refer to the following CloudScript code to get the user’s location.

handlers.GetUserLocation = function (args, context) {

    var request = {
        "PlayFabId": currentPlayerId,
        "InfoRequestParameters": {
            "GetPlayerProfile": true,
            "ProfileConstraints":
            {
                "ShowLocations": true
            }
        }
    };

    var getUserInfo = server.GetPlayerCombinedInfo(request);
    var userLocation = getUserInfo.InfoResultPayload.PlayerProfile.Locations;
    return { userLocation: userLocation };
};
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.

Talha avatar image Talha commented ·

Phew! Thanks Alot. It's working now.

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.