Record Score
API for recording a score to the leaderboard.
URL Verification
This API uses the service-api.playnanoo.com domain.
API Information
- URL:
https://service-api.playnanoo.com/leaderboard/v20240301/record - Method:
PUT - Authentication Required: Yes
DeviceInfo Inheritance
The Req class of this API inherits from DeviceInfo. All properties of DeviceInfo are automatically included.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| uid | string | Required | Table code |
| record_id | string | Required | Record ID (player identifier) |
| score | double | Required | Score |
| extra_data | string | Yes | Additional data (JSON string) |
Response Data
Res Class
| Field | Type | Description |
|---|---|---|
| Status | string | Processing status |
Unity C# Implementation
BaseResponse Class
Base class for all API responses.
public class BaseResponse
{
public string ErrorCode;
public string Message;
public string WithdrawalKey;
public string BlockKey;
}
Field descriptions:
ErrorCode: Error codeMessage: Error messageWithdrawalKey: Key required for recovery if in withdrawal grace period (only provided for accounts in withdrawal grace period)BlockKey: Key provided if account is blocked (only provided for blocked accounts)
Record Score Class
using System;
using System.Collections;
using UnityEngine.Networking;
public class Record
{
static string path = "https://service-api.playnanoo.com/leaderboard/v20240301/record";
[Serializable]
public class Req : DeviceInfo
{
public string uid;
public string record_id;
public double score;
public string extra_data;
public IEnumerator Send(string table_code, string recordId, double score, string extraData, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(table_code)) this.uid = table_code;
if (!string.IsNullOrEmpty(recordId)) this.record_id = recordId;
if (!string.IsNullOrEmpty(extraData)) this.extra_data = extraData;
this.score = score;
yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}
[Serializable]
public class Res : BaseResponse
{
public string Status;
}
}
Usage Example
public void RecordScore()
{
Record.Req req = new Record.Req();
// Serialize additional data to JSON
var extraData = new
{
level = 10,
playtime = 3600
};
string jsonExtra = JsonUtility.ToJson(extraData);
StartCoroutine(req.Send(
table_code: "my_leaderboard_table",
recordId: "player_001",
score: 1500.5,
extraData: jsonExtra,
onSuccess: res =>
{
Debug.Log("Score recorded successfully");
Debug.Log($"Status: {res.Status}");
},
onError: error =>
{
Debug.LogError($"Score recording failed: [{error.ErrorCode}] {error.Message}");
}
));
}
Score Recording
Recorded scores are processed according to the table settings (record_type):
- highscore: Keep only the highest score
- lowscore: Keep only the lowest score
- sum: Sum all scores
- last: Update to the most recent score
Additional Data
extra_data can include additional information to store with the score, such as player level, play time, item information, etc., in JSON format.