Display a player's ranking using the Leaderboard v1 (Legacy)
Overview
The AccelByte Gaming Services (AGS) Leaderboard service empowers you to create a competitive atmosphere amongst players, by displaying the Leaderboard and providing information about player ranking.
This article walks you through how to use the SDK to retrieve a Leaderboard and a specific player's ranking.
Prerequisites
- Access to the AGS Admin Portal.
- Access to the AGS SDK for Unreal or Unity.
- Access to the AGS Leaderboard API documentation for reference.
Display the Leaderboard Rankings
To display the Leaderboard rankings, you need to get the Leaderboard data. The data will be returned for the specified life cycle of the Leaderboard (daily, weekly, monthly, etc.). You can also specify a limit to the number of players that you want to retrieve data on (for example, top 10, or top 50). And you can specify an offset, so you can retrieve the next 10, next 50, and so on, if you wish to display the Leaderboard in pages.
You can use the following function to get the Leaderboard rankings:
Get Leaderboard rankings
- Unreal Engine
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FString LeaderboardCode = FString("SomeLeaderboardCode");
EAccelByteLeaderboardTimeFrame TimeFrame = EAccelByteLeaderboardTimeFrame::ALL_TIME;
int32 Offset = 0;
int32 Limit = 99;
FRegistry::Leaderboard.GetRankings(LeaderboardCode, TimeFrame, Offset, Limit, THandler<FAccelByteModelsLeaderboardRankingResult>::CreateLambda([](const FAccelByteModelsLeaderboardRankingResult& Result)
{
// Do something if GetRankings succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetRankings fails
}));
var leaderboard = AccelByteSDK.GetClientRegistry().GetApi().GetLeaderboard();
string leaderboardCode = "SomeLeaderboardCode";
LeaderboardTimeFrame timeFrame= LeaderboardTimeFrame.ALL_TIME;
int offset = 0;
int limit = 99;
leaderboard.GetRankings(leaderboardCode, timeFrame, offset, limit, result =>
{
if (result.IsError)
{
// Do something if GetRankings fails
Debug.Log($"Error GetRankings, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if GetRankings is successful
});
leaderboardDataService := &leaderboard.LeaderboardDataService{
Client: factory.NewLeaderboardClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
leaderboardCode := "myleaderboardcode"
namespace := "mygame"
limit := int64(50)
offset := int64(0)
input := &leaderboard_data.GetAllTimeLeaderboardRankingPublicV1Params{
LeaderboardCode: leaderboardCode,
Namespace: namespace,
Limit: &limit,
Offset: &offset,
}
result, err := leaderboardDataService.GetAllTimeLeaderboardRankingPublicV1Short(input)
import accelbyte_py_sdk.api.leaderboard as leaderboard_service
# all_time: get_all_time_leaderboard_ranking_public_v3 (GET /leaderboard/v1/public/namespaces/{namespace}/leaderboards/{leaderboardCode}/alltime)
# season: get_current_season_leaderboard_ranking_public_v1 (GET /leaderboard/v1/public/namespaces/{namespace}/leaderboards/{leaderboardCode}/season)
# month: get_current_month_leaderboard_ranking_public_v1 (GET /leaderboard/v1/public/namespaces/{namespace}/leaderboards/{leaderboardCode}/month)
# week: get_current_week_leaderboard_ranking_public_v1 (GET /leaderboard/v1/public/namespaces/{namespace}/leaderboards/{leaderboardCode}/week)
# today: get_today_leaderboard_ranking_public_v1 (GET /leaderboard/v1/public/namespaces/{namespace}/leaderboards/{leaderboardCode}/today)
result, error = leaderboard_service.get_all_time_leaderboard_ranking_public_v3(
leaderboard_code="SomeLeaderboardCode",
limit=99,
offset=0,
)
if error:
exit(error)
final LeaderboardData leaderboardDataWrapper = new LeaderboardData(sdk);
String leaderboardCode = "<my-leaderboard-code>";
ModelsGetLeaderboardRankingResp response;
try {
response = leaderboardDataWrapper.getAllTimeLeaderboardRankingPublicV1(GetAllTimeLeaderboardRankingPublicV1.builder()
.namespace("<namespace>")
.leaderboardCode(leaderboardCode)
.offset(0)
.limit(50)
.build());
} catch (Exception e) {
// Do something if an error occurs
return;
}
if (response == null) {
// Null response from server
} else {
// Do something if successful
}
string leaderboardCode = "<my-leaderboard-code>";
var response = sdk.Leaderboard.LeaderboardData.GetAllTimeLeaderboardRankingPublicV1Op
.SetOffset(0)
.SetLimit(50)
.Execute(leaderboardCode, sdk.Namespace);
if (response != null)
{
// Do something if successful
}
Display a player's ranking
You can display or highlight a specific player's rank.
Get specific player's ranking
You can get a specific player's ranking using the User ID, with the following function:
- Unreal Engine
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FString UserId = FString("SomeUserId");
FString LeaderboardCode = FString("SomeLeaderboardCode");
FRegistry::Leaderboard.GetUserRanking(UserId, LeaderboardCode, THandler<FAccelByteModelsUserRankingData>::CreateLambda([](const FAccelByteModelsUserRankingData& Result)
{
// Do something if GetUserRanking succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetUserRanking fails
}));
var leaderboard = AccelByteSDK.GetClientRegistry().GetApi().GetLeaderboard();
string userId = "SomeUserId";
string leaderboardCode = "SomeLeaderboardCode";
leaderboard.GetUserRanking(userId, leaderboardCode, result =>
{
if (result.IsError)
{
// Do something if GetUserRanking fails
Debug.Log($"Error GetUserRanking, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if GetUserRanking is successful
});
leaderboardDataService := &leaderboard.LeaderboardDataService{
Client: factory.NewLeaderboardClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
leaderboardCode := "myleaderboardcode"
namespace := "mygame"
userId := "myuserid"
input := &leaderboard_data.GetUserRankingPublicV1Params{
LeaderboardCode: leaderboardCode,
Namespace: namespace,
UserID: userId,
}
result, err := leaderboardDataService.GetUserRankingPublicV1Short(input)
import accelbyte_py_sdk.api.leaderboard as leaderboard_service
result, error = leaderboard_service.get_user_ranking_public_v1(
leaderboard_code="SomeLeaderboardCode",
user_id="********************************",
)
if error:
exit(error)
final LeaderboardData leaderboardDataWrapper = new LeaderboardData(sdk);
String leaderboardCode = "<my-leaderboard-code>";
String userId = "<user-id>";
ModelsUserRankingResponse response;
try {
response = leaderboardDataWrapper.getUserRankingPublicV1(GetUserRankingPublicV1.builder()
.namespace("<namespace>")
.userId(userId)
.leaderboardCode(leaderboardCode)
.build());
} catch (Exception e) {
// Do something if an error occurs
return;
}
if (response == null) {
// Null response from server
} else {
// Do something if successful
}
string leaderboardCode = "<my-leaderboard-code>";
string userId = "<user-id>";
var response = sdk.Leaderboard.LeaderboardData.GetUserRankingPublicV1Op
.Execute(leaderboardCode, sdk.Namespace, userId);
if (response != null)
{
// Do something if successful
}