PostScoreToDynamicLeaderboardUsingConfig
Post the player's score to the given social leaderboard, dynamically creating the leaderboard if it does not exist yet. To create new leaderboard, configJson must specify leaderboardType, rotationType, resetAt, and retainedCount, at a minimum, with support to optionally specify an expiry in minutes.
Service | Operation |
---|---|
leaderboard | POST_SCORE_DYNAMIC_USING_CONFIG |
info
This new API call has been added to provide increased flexibility compared to the previous methods. It enables the developer to set a parameter of expireInMins, which queues the leaderboard for deletion after the designated number of minutes.
Method Parameters
Parameter | Description |
---|---|
leaderboardId | The leaderboard to post to. |
score | A score to post. |
scoreData | Optional user-defined data to post with the score. |
configJson | Configuration for the leaderboard if it does not exist yet, specified as JSON object. The supporting configuration fields are listed in the following table of configJson fields. |
configJson fields
Parameter | Description |
---|---|
leaderboardType | Required. Type of leaderboard. Valid values are 'LAST_VALUE', 'HIGH_VALUE', 'LOW_VALUE', 'CUMULATIVE', 'ARCADE_HIGH', 'ARCADE_LOW'; |
rotationType | Required. Type of rotation. Valid values are 'NEVER', 'DAILY', 'DAYS', 'WEEKLY', 'MONTHLY', 'YEARLY'; |
numDaysToRotate | Required if 'DAYS' rotation type, with valid values between 2 and 14; otherwise, null; |
resetAt | UTC timestamp, in milliseconds, at which to rotate the period. Always null if 'NEVER' rotation type; |
retainedCount | Required. Number of rotations (versions) of the leaderboard to retain; |
expireInMins | Optional (but highly recommended). Duration, in minutes, before the leaderboard is to automatically expire. This ensures that the leaderboards are automatically cleaned up after the specified amount of time. |
Usage
http://localhost:3000
- C#
- C++
- Objective-C
- Java
- JavaScript
- Dart
- Cloud Code
- Raw
string leaderboardId = "aLeaderboardId";
int score = 10;
string scoreData = "{\"nickname\": \"batman\"}";
string configJson = "{\"leaderboardType\": \"HIGH_VALUE\", \"rotationType\": \"DAYS\", \"numDaysToRotate\": 4, \"resetAt\": \"[[#ts+60000]]\", \"retainedCount\": 2, \"expireInMins\": \"None\"}";
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("Success | {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("Failed | {0} {1} {2}", status, code, error));
};
_bc.LeaderboardService.PostScoreToDynamicLeaderboardUsingConfig(leaderboardId, score, scoreData, configJson, successCallback, failureCallback);
const char *leaderboardId = "aLeaderboardId";
int score = 10;
const char *scoreData = "{\"nickname\": \"batman\"}";
const char *configJson = "{\"leaderboardType\": \"HIGH_VALUE\", \"rotationType\": \"DAYS\", \"numDaysToRotate\": 4, \"resetAt\": \"[[#ts+60000]]\", \"retainedCount\": 2, \"expireInMins\": \"None\"}";
_bc.getLeaderboardService().postScoreToDynamicLeaderboardUsingConfig(leaderboardId, score, scoreData, configJson, this);
NSString *leaderboardId = @"aLeaderboardId";
int score = 10;
NSString *scoreData = @"{\"nickname\": \"batman\"}";
NSString *configJson = @"{\"leaderboardType\": \"HIGH_VALUE\", \"rotationType\": \"DAYS\", \"numDaysToRotate\": 4, \"resetAt\": \"[[#ts+60000]]\", \"retainedCount\": 2, \"expireInMins\": \"None\"}";
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc leaderboardService] postScoreToDynamicLeaderboardUsingConfig:
leaderboardId:leaderboardId
score:score
scoreData:scoreData
configJson:configJson
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil]
String leaderboardId = "aLeaderboardId";
int score = 10;
String scoreData = "{\"nickname\": \"batman\"}";
String configJson = "{\"leaderboardType\": \"HIGH_VALUE\", \"rotationType\": \"DAYS\", \"numDaysToRotate\": 4, \"resetAt\": \"[[#ts+60000]]\", \"retainedCount\": 2, \"expireInMins\": \"None\"}";
this; // implements IServerCallback
_bc.getLeaderboardService.postScoreToDynamicLeaderboardUsingConfig(leaderboardId, score, scoreData, configJson, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var leaderboardId = "aLeaderboardId";
var score = 10;
var scoreData = {
"nickname": "batman"
};
var configJson = {
"leaderboardType": "HIGH_VALUE",
"rotationType": "DAYS",
"numDaysToRotate": 4,
"resetAt": "[[#ts+60000]]",
"retainedCount": 2,
"expireInMins": null
};
_bc.leaderboard.postScoreToDynamicLeaderboardUsingConfig(leaderboardId, score, scoreData, configJson, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
var leaderboardId = "aLeaderboardId";
var score = 10;
var scoreData = {
"nickname": "batman"
};
var configJson = {
"leaderboardType": "HIGH_VALUE",
"rotationType": "DAYS",
"numDaysToRotate": 4,
"resetAt": "[[#ts+60000]]",
"retainedCount": 2,
"expireInMins": null
};
ServerResponse result = await _bc.leaderboardService.postScoreToDynamicLeaderboardUsingConfig(leaderboardId:leaderboardId, score:score, scoreData:scoreData, configJson:configJson);
if (result.statusCode == 200) {
print("Success");
} else {
print("Failed ${result.error['status_message'] ?? result.error}");
}
var leaderboardId = "aLeaderboardId";
var score = 10;
var scoreData = {
"nickname": "batman"
};
var configJson = {
"leaderboardType": "HIGH_VALUE",
"rotationType": "DAYS",
"numDaysToRotate": 4,
"resetAt": "[[#ts+60000]]",
"retainedCount": 2,
"expireInMins": null
};
var leaderboardProxy = bridge.getLeaderboardServiceProxy();
var postResult = leaderboardProxy.postScoreToDynamicLeaderboardUsingConfig(leaderboardId, score, scoreData, configJson);
{
"service":"leaderboard",
"operation":"POST_SCORE_DYNAMIC_USING_CONFIG",
"data":{
"leaderboardId":"aLeaderboardId",
"score":10,
"scoreData":{
"nickname":"batman"
},
"configJson":{
"leaderboardType":"HIGH_VALUE",
"rotationType":"DAYS",
"numDaysToRotate":4,
"resetAt":"[[#ts+60000]]",
"retainedCount":2,
"expireInMins":null
}
}
}
JSON Response
{
"status": 200,
"data": null
}