# 抖音小游戏服务端
# 获取小游戏接口调用凭证
# 请求地址
GET https://api.mcfrogtech.com/minigame/tt/apps/token
# 请求参数
参数 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
app_id | string | 无 | 是 | 小游戏id |
app_secret | string | 无 | 是 | 小游戏app_secret |
# 响应参数
参数 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
code | number | 无 | 是 | 状态码,0表示成功,-1表示失败。 |
message | string | 无 | 是 | 消息。 |
data | { access_token: string } | 无 | 否 | 响应数据。access_token是返回的接口调用凭证。 |
# 请求须知
发行服务会自动维护access_token的更新,cp不需要缓存或者主动更新access_token,使用时即时调用发行服务接口获取最新access_token即可。
# 请求示例
GET https://api.mcfrogtech.com/minigame/tt/apps/token?app_id=your_appid&app_secret=your_appsecret
# 响应示例
{
"code": 0,
"message": "",
"data": {
"access_token": "your_token"
}
}
# 抖音小游戏客户端
# 获取用户信息
# 方法定义
export interface GetUserInfoOptions {
withCredentials?: boolean;
}
export interface UserInfo {
avatarUrl: string;
nickName: string;
gender: number;
city: string;
province: string;
country: string;
language: string;
openId?: string;
unionId?: string;
watermark?: {
appid: string;
timestamp: number;
};
}
function getUserInfo(options: GetUserInfoOptions): Promise<UserInfo>;
# 参数介绍
参数 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
options | GetUserInfoOptions | 无 | 是 | withCredentials字段用来告知SDK是否获取并解密用户敏感数据。 |
# 返回值介绍
返回UserInfo对象,属性如下:
属性 | 类型 | 说明 |
---|---|---|
avatarUrl | string | 用户头像。 |
nickName | string | 用户名。 |
gender | number | 用户性别,0: 未知;1:男性;2:女性。withCredentials为false 返回0,为true 返回用户性别。 |
city | string | 用户城市。 withCredentials为false 返回"",为true 返回用户城市。 |
province | string | 用户省份。 withCredentials为false 返回"",为true 返回用户省份。 |
country | string | 用户国家。 withCredentials为false 返回"",为true 返回用户国家。 |
language | string | 用户语言。 withCredentials为false 返回"",为true 返回用户语言。 |
openId | string | 用户openId。withCredentials为true 返回。 |
unionId | string | 用户unionId。withCredentials为true 返回。 |
watermark | { appid: string; timestamp: number } | 敏感数据水印。withCredentials为true 返回。 |
# 调用示例
必须在ttAppSdk.login
方法调用成功后调用。
ttAppSDK.login().then(data => {
console.log('sdk登录成功', data);
ttAppSDK.getUserInfo({
withCredentials: true,
}).then((res) => {
console.log("获取用户信息成功", res);
}).catch((e) => {
console.error("获取用户信息失败", e);
})
});