Returns leaderboard data that only contains entries of players that are game friends with the current player.

The GameSparks platform will attempt to return players both ahead and behind the current player, where data is available.

The entry count defines how many player should be returned both ahead and behind. The numer of results may vary if there are not enough friends either ahead or behind.

View interactive version here

Request Parameters

Parameter Required Type Description
challengeInstanceId No string The challenge instance to get the leaderboard data for
dontErrorOnNotSocial No boolean The default behavior on a social request is to error if the player has no friends (NOTSOCIAL). Set this flag to suppress that error and return the player's leaderboard entry instead.
entryCount Yes number The number of items to return in a page (default=50)
friendIds No string[] A friend id or an array of friend ids to use instead of the player's social friends
includeFirst No number Number of entries to include from head of the list
includeLast No number Number of entries to include from tail of the list
inverseSocial No boolean Returns the leaderboard excluding the player's social friends
leaderboardShortCode No string The short code of the leaderboard
offset No number The offset into the set of leaderboards returned
social No boolean If True returns a leaderboard of the player's social friends
teamIds No string[] Use this to specify the teams whose Leaderboard data you are interested in. If social is set to True, the request returns the current Leaderboard data for only those players for the specified teams that are friends of the player making the request.
teamTypes No string[] Use this to specify the team types whose Leaderboard data you are interested in. If social is set to True, the request returns the current Leaderboard data for only those players for the specified team types that are friends of the player making the request.

Response Parameters

A response containing leaderboard data

Parameter Type Description
challengeInstanceId string The leaderboard's challenge id
data LeaderboardData[] The leaderboard data
first LeaderboardData[] The first item in the leaderboard data
last LeaderboardData[] The last item in the leaderboard data
leaderboardShortCode string The leaderboard short code
scriptData ScriptData A JSON Map of any data added either to the Request or the Response by your Cloud Code

Nested types


A collection of arbitrary data that can be added to a message via a Cloud Code script.

Parameter Type Description
myKey string An arbitrary data key
myValue JSON An arbitrary data value.


Leaderboard entry data

As well as the parameters below there may be others depending on your game's configuration.

Parameter Type Description
city string The city where the player was located when they logged this leaderboard entry.
country string The country code where the player was located when they logged this leaderboard entry.
externalIds JSON The players rank.
rank number The players rank.
userId string The unique player id for this leaderboard entry.
userName string The players display name.
when string The date when this leaderboard entry was created.

Error Codes

Key Value Description
leaderboardShortCode|challengeInstanceId ONLY_ONE Both shortCode and challengeInstanceId were supplied, only one should be supplied
leaderboardShortCode|challengeInstanceId REQUIRED Both shortCode and challengeInstanceId were missing
leaderboardShortCode INVALID The shortCode does not match a configured leaderboard
currentUser NOTSOCIAL The current player does not have any game friends
challengeInstanceId NO_LEADERBOARD The challengeInstanceId maps to a challenge without a leaderboard configured
challengeInstanceId INVALID The challengeInstanceId supplied did not match a challenge related to the current play

Code Samples


    using GameSparks.Api;
    using GameSparks.Api.Requests;
    using GameSparks.Api.Responses;
    new SocialLeaderboardDataRequest()
        .Send((response) => {
        string challengeInstanceId = response.ChallengeInstanceId;
        GSEnumerable<LeaderboardDataResponse._LeaderboardData> data = response.Data;
        GSEnumerable<LeaderboardDataResponse._LeaderboardData> first = response.First;
        GSEnumerable<LeaderboardDataResponse._LeaderboardData> last = response.Last;
        string leaderboardShortCode = response.LeaderboardShortCode;
        GSData scriptData = response.ScriptData;

ActionScript 3

    import com.gamesparks.*;
    import com.gamesparks.api.requests.*;
    import com.gamesparks.api.responses.*;
    import com.gamesparks.api.types.*;

        .send(function(response:com.gamesparks.api.responses.LeaderboardDataResponse):void {
        var challengeInstanceId:String = response.getChallengeInstanceId(); 
        var data:Vector.<LeaderboardData> = response.getData(); 
        var first:Vector.<LeaderboardData> = response.getFirst(); 
        var last:Vector.<LeaderboardData> = response.getLast(); 
        var leaderboardShortCode:String = response.getLeaderboardShortCode(); 
        var scriptData:ScriptData = response.getScriptData(); 


    #import "GS.h"
    #import "GSAPI.h"
    GSSocialLeaderboardDataRequest* request = [[GSSocialLeaderboardDataRequest alloc] init];
    [request setChallengeInstanceId:challengeInstanceId;
    [request setDontErrorOnNotSocial:dontErrorOnNotSocial;
    [request setEntryCount:entryCount;
    [request setFriendIds:friendIds;
    [request setIncludeFirst:includeFirst;
    [request setIncludeLast:includeLast;
    [request setInverseSocial:inverseSocial;
    [request setLeaderboardShortCode:leaderboardShortCode;
    [request setOffset:offset;
    [request setSocial:social;
    [request setTeamIds:teamIds;
    [request setTeamTypes:teamTypes;
    [request setCallback:^ (GSLeaderboardDataResponse* response) {
    NSString* challengeInstanceId = [response getChallengeInstanceId]; 
    NSArray* data = [response getData]; 
    NSArray* first = [response getFirst]; 
    NSArray* last = [response getLast]; 
    NSString* leaderboardShortCode = [response getLeaderboardShortCode]; 
    NSDictionary* scriptData = [response getScriptData]; 
    [gs send:request];


    #include <GameSparks/generated/GSRequests.h>
    using namespace GameSparks::Core;
    using namespace GameSparks::Api::Responses;
    using namespace GameSparks::Api::Requests;

    void SocialLeaderboardDataRequest_Response(GS& gsInstance, const LeaderboardDataResponse& response) {
    gsstl::string challengeInstanceId = response.getChallengeInstanceId(); 
    gsstl:vector<Types::LeaderboardData*> data = response.getData(); 
    gsstl:vector<Types::LeaderboardData*> first = response.getFirst(); 
    gsstl:vector<Types::LeaderboardData*> last = response.getLast(); 
    gsstl::string leaderboardShortCode = response.getLeaderboardShortCode(); 
    GSData scriptData = response.getScriptData(); 

    SocialLeaderboardDataRequest request(gsInstance);


import com.gamesparks.sdk.api.autogen.GSRequestBuilder.SocialLeaderboardDataRequest;
import com.gamesparks.sdk.api.autogen.GSResponseBuilder.LeaderboardDataResponse;
import com.gamesparks.sdk.api.autogen.GSTypes.*;
import com.gamesparks.sdk.api.GSEventListener;

    .send(new GSEventListener<LeaderboardDataResponse>() {
        public void onEvent(LeaderboardDataResponse response) {
            String challengeInstanceId = response.getChallengeInstanceId(); 
            List<LeaderboardData> data = response.getData(); 
            List<LeaderboardData> first = response.getFirst(); 
            List<LeaderboardData> last = response.getLast(); 
            String leaderboardShortCode = response.getLeaderboardShortCode(); 

Cloud Code

    var request = new SparkRequests.SocialLeaderboardDataRequest();
    request.challengeInstanceId = ...;
    request.dontErrorOnNotSocial = ...;
    request.entryCount = ...;
    request.friendIds = ...;
    request.includeFirst = ...;
    request.includeLast = ...;
    request.inverseSocial = ...;
    request.leaderboardShortCode = ...;
    request.offset = ...; = ...;
    request.teamIds = ...;
    request.teamTypes = ...;
    var response = request.Send();

var challengeInstanceId = response.challengeInstanceId; 
var data =; 
var first = response.first; 
var last = response.last; 
var leaderboardShortCode = response.leaderboardShortCode; 
var scriptData = response.scriptData;