Sign In Register

How can we help you today?

Start a new topic
Answered

get player country from cloud code

 Hi ,


we are working on implementing leaderboard but we need to also show the country next to each player.


I look through the documentation but didn't know how to get the country for a player.


Thanks


Best Answer

Hi Ahmed


Sorry for the late reply.

You can get the players country using a AccountDetailsRequest

In cloud code this will be


var accountDetailsRequest = new SparkRequests.AccountDetailsRequest;
var response = Spark.sendRequestAs(accountDetailsRequest, playerId);


This will return the location json

var location = response.location;


To get the country

var country = location.country


The documentation on Account details request can be found here


Thanks

Katie






Answer

Hi Ahmed


Sorry for the late reply.

You can get the players country using a AccountDetailsRequest

In cloud code this will be


var accountDetailsRequest = new SparkRequests.AccountDetailsRequest;
var response = Spark.sendRequestAs(accountDetailsRequest, playerId);


This will return the location json

var location = response.location;


To get the country

var country = location.country


The documentation on Account details request can be found here


Thanks

Katie






1 person likes this

Is there a way to get the player's country code from WITHIN the AccountDetailsResponse cloud code? It seems like the data that's in the response should be available for this code to read.

Nevermind my last question. I found the answer:

Spark.getData();


Login to post a comment