How to Access Leaderboards via Cloud Code

There are many scenarios where you might want to access Leaderboard data. For example, you might want to:

You can implement these two features using the Cloud Code SparkRequests API. This API allows requests to be sent either as the current player or as any other player within your game.

To find the rank of a given player, you can use a LeaderboardDataRequest, which will return the data associated with the player:

    var request = new SparkRequests.LeaderboardDataRequest();
    request.entryCount = 1;
    request.leaderboardShortCode = "leaderboardSC";

    var response = request.Send();

Now you'll have the GameSparks response stored in your response variable as a JSON object.

Did this page help you? Please enter your feedback below. For questions about using this part of the platform, please contact support here