# LeaderboardManager.loadCurrentPlayerLeaderboardScore
以 Promise 风格调用:不支持
# 功能描述
获取当前登录用户在指定排行榜的分数和排名。
# 参数
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| leaderboardId | string | 是 | 排行榜ID | |
| collection | string | public | 否 | 榜单类型: • "friends"(需隐私协议授权) • "public"(无需授权) |
| periodToken | string | 否 | 时间周期标识: • 无重置周期:传空或不传 • 有重置周期:需匹配周期时间戳(如"1745118000-1745636399") | |
| callback | Object | 否 | 接口调用结果回调 |
callback:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| onSuccess | function | 否 | 接口调用成功的回调函数 | |
| onFailure | function | 否 | 接口调用失败的回调函数 |
onSuccess回调返回数据:
Object res:
| 属性名 | 数据类型 | 说明 |
|---|---|---|
| currentUserScore | Score | 当前用户的分数信息 |
| leaderboard | Leaderboard | 排行榜信息 |
Score:
| 属性名 | 类型 | 说明 |
|---|---|---|
| rank | number | 用户排名 |
| rankDisplay | string | 排名展示文本(如"1000+") |
| score | number | 用户分数 |
| scoreDisplay | string | 分数展示文本(如"1999万 战力"),无成绩不显示 |
| user | User | 用户信息 |
User:
| 属性名 | 类型 | 说明 |
|---|---|---|
| avatar | Image | 用户头像 |
| name | string | 用户名称 |
| openid | string | Open ID(TapTap用户在小游戏中的唯一标识) |
| unionid | string | Union ID(TapTap用户在同一开发者下所有应用中的唯一标识) |
LeaderBoard:
| 属性名 | 数据类型 | 说明 |
|---|---|---|
| availablePeriods | Array.<Period> | 可用的时间周期 |
| background | Image | 排行榜背景 |
| id | string | 排行榜ID |
| name | string | 排行榜名称 |
| period | Period | 排行榜周期 |
| score | Score | 排行榜分数 |
Period:
| 属性名 | 类型 | 说明 |
|---|---|---|
| display | string | 展示文本,如"4月20日 - 4月26日",永久榜单为空 |
| periodToken | string | 时间周期标识,示例:"1745118000-1745636399" |
Image:
| 属性名 | 类型 | 说明 |
|---|---|---|
| color | string | 十六进制的颜色代码 |
| gifUrl | string | GIF的URL |
| height | number | 高度(像素) |
| width | number | 宽度(像素) |
| mediumUrl | string | 中等图片的URL |
| originalFormat | string | 原始的格式 |
| originalSize | number | 原始的尺寸 |
| originalUrl | string | 原始图片的URL |
| smallUrl | string | 小图片的URL |
| url | string | 图片的URL |
# 错误
1025、104、103错误码,在collection参数为"friends"时可能遇到,若遇到1025错误码,请参照权限说明部分修改小游戏后台配置。
| 错误码 | 错误信息 | 说明 |
|---|---|---|
| 500000 | 排行榜周期已过期 | 提示用户排行榜周期已结束,引导查看其他周期 |
| 500001 | 排行榜 ID 未找到 | 排行榜 ID 不存在 |
| 500002 | 排行榜参数错误 | 排行榜 ID 与游戏不匹配 |
| 1025 | 小游戏没有申明使用好友关系信息 | 开发者在后台没有在隐私协议中申明使用好友关系,调用需要好友关系权限的 API 时会返回此错误码 |
| 104 | 用户未通过隐私协议 | 调用需要好友关系权限的 API 时,用户没有通过隐私协议则返回该错误码 |
| 103 | 用户未授权使用其好友关系信息 | 调用需要好友关系权限的 API 时,用户没有授权使用好友信息则返回该错误码 |
| 500201 | leaderboardId 为空 | 提示传入正确的 leaderboardId |
# 示例代码
tapLeaderboard.loadCurrentPlayerLeaderboardScore({
leaderboardId: "your_leaderboardId", // 排行榜 ID
collection: "public", // 总榜
periodToken: "", // 时间周期标识(可为空)
callback: {
onSuccess: function(res) {
console.log("loadCurrentPlayerLeaderboardScore success:", JSON.stringify(res, null, 2));
},
onFailure: function(code, message) {
console.error(`loadCurrentPlayerLeaderboardScore failed: code=${code}, message=${message}`);
}
}
});
