获取用户公开资料 · Get Public User Profile
根据 userId 获取用户的公开主页资料,包括昵称、头像、简介、等级与社交统计等。常用于作者主页、排行榜用户卡片、群聊房主信息等场景。
本接口始终以陌生人视角返回数据。即使查询的是自己的
userId,也不会返回完整私有资料;查看自己的完整资料请使用get-user-profile。
接口地址
POST https://xiangcao.ai/api/get-public-user-profile
普通(非流式)接口,走
/api前缀。
鉴权
这是公开接口,鉴权可选:
- 不带 Token 也能调用。
- 携带 Token 时会按用户做调用频率限制(rate limit),且当查询的不是自己时会额外返回
isFollowing字段:
Authorization: Bearer <YOUR_API_KEY>
请求体(JSON)
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
userId | string | 是 | 目标用户 ID。 |
类型定义(TypeScript)
interface GetPublicUserProfileRequest {
/** 目标用户 ID */
userId: string;
}
响应(JSON)
直接返回 PublicUserProfile 对象(非分页结构)。
| 字段 | 类型 | 说明 |
|---|---|---|
userId | string | 用户 ID。 |
nickname | string | null | 昵称(含链接的昵称会被替换为占位文案)。 |
avatarUrl | string | null | 头像 URL。 |
profileBgUrl | string | null | 主页背景图 URL。 |
bio | string | null | 个人简介。 |
statusStickerUrl | string | null | 状态贴纸 URL。 |
createdAt | number | 注册时间(毫秒时间戳)。 |
updatedAt | number | 最近更新时间(毫秒时间戳)。 |
vipLevel | number | VIP 等级(0–30)。用户 opt-out 公开金主身份时不返回。 |
authorLevel | number | 作者等级(0–30)。 |
isMember | boolean | 是否为有效会员。用户 opt-out 公开金主身份时不返回。 |
isOfficial | boolean | 是否为平台官方账号(仅官方账号返回)。 |
followerCount | number | 粉丝数。 |
followingCount | number | 关注数。 |
cardCount | number | 创作的角色卡数量。 |
topAuthorRank | number | 作者榜名次(1–15),未上榜则不返回。 |
topVipRank | number | 金主榜名次(1–15),未上榜则不返回;用户 opt-out 时不返回。 |
isFollowing | boolean | 当前 Token 用户是否已关注该用户(仅登录且查询他人时返回)。 |
hideSocialFromPublic | boolean | 用户已隐藏社交清单时为 true,前端可据此展示锁定提示。 |
类型定义(TypeScript)
interface PublicUserProfile {
userId: string;
nickname: string | null;
avatarUrl: string | null;
profileBgUrl: string | null;
bio: string | null;
statusStickerUrl: string | null;
createdAt: number;
updatedAt?: number;
vipLevel?: number;
authorLevel?: number;
isMember?: boolean;
isOfficial?: boolean;
followerCount?: number;
followingCount?: number;
cardCount?: number;
topAuthorRank?: number;
topVipRank?: number;
isFollowing?: boolean;
hideSocialFromPublic?: boolean;
}
响应示例:
{
"userId": "user_001",
"nickname": "香草作者",
"avatarUrl": "https://cdn.xiangcao.ai/avatars/user_001.png",
"profileBgUrl": null,
"bio": "喜欢写角色卡",
"statusStickerUrl": null,
"createdAt": 1700000000000,
"updatedAt": 1705000000000,
"vipLevel": 5,
"authorLevel": 12,
"isMember": true,
"followerCount": 128,
"followingCount": 32,
"cardCount": 8,
"topAuthorRank": 3,
"isFollowing": false
}
示例
curl -X POST "https://xiangcao.ai/api/get-public-user-profile" \
-H "Authorization: Bearer <YOUR_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"userId": "user_001"
}'
错误处理
出错时返回相应 HTTP 状态码及 JSON。
| 状态码 | 说明 |
|---|---|
400 | 缺少 userId。 |
401 | Token 无效或账号被封禁(公开调用可不带 Token)。 |
404 | 用户不存在,或用户已被封禁。 |
500 | 服务端内部错误。 |