更新账号显示名
修改当前账号的显示名,返回更新后的账号。
PATCH
/api/account/profile请求参数
| 参数 | 类型 | 位置 | 必填 | 说明 |
|---|---|---|---|---|
name | string | body | 是 | 新的显示名,1–60 个字符。 |
请求示例
JavaScript 示例可在本站已登录的浏览器中运行。cURL 和 Python 示例读取你本机的 cookies.txt Cookie 文件。请将会话 Cookie 视为私密凭据。
cURL
curl -i -X PATCH 'https://social2api.com/api/account/profile' \
--cookie ./cookies.txt \
-H 'Content-Type: application/json' \
-H 'Origin: https://social2api.com' \
--data-binary '{
"name": "API Reader"
}'Python
from urllib.error import HTTPError
from urllib.request import Request, HTTPCookieProcessor, build_opener
from http.cookiejar import MozillaCookieJar
request = Request(
"https://social2api.com/api/account/profile",
method="PATCH",
headers={
"Content-Type": "application/json",
"Origin": "https://social2api.com",
},
data="{\"name\":\"API Reader\"}".encode("utf-8"),
)
cookies = MozillaCookieJar("./cookies.txt")
cookies.load(ignore_discard=True)
send = build_opener(HTTPCookieProcessor(cookies)).open
try:
with send(request) as response:
print(response.status, response.read().decode("utf-8"))
except HTTPError as error:
print(error.code, error.read().decode("utf-8"))JavaScript
const response = await fetch("/api/account/profile", {
method: "PATCH",
credentials: "same-origin",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
"name": "API Reader"
}),
});
console.log(response.status, await response.text());响应
200 · 示例响应
{
"account": {
"id": "a2508bc7-316a-4d0c-93ab-ba87f7c3545e",
"email": "reader@example.com",
"name": "API Reader",
"createdAt": "2026-01-15T12:00:00.000Z",
"emailVerified": false,
"hasPassword": true,
"preferences": {}
}
}错误示例
{
"error": "账户服务暂不可用,请稍后重试。"
}| 字段 | 类型 | 说明 |
|---|---|---|
account | object | 当前操作涉及的账号。 |
account.id | string | 账号 ID。 |
account.email | string | 规范化的邮箱地址。 |
account.name | string | 显示名。 |
account.createdAt | ISO 8601 date-time | 账号创建时间。 |
account.emailVerified | boolean | 邮箱是否通过验证。 |
account.hasPassword | boolean | 该账号是否已设置密码。 |
account.preferences | object | 已存储的账号偏好。 |
错误状态
| HTTP | 原因与处理 |
|---|---|
400 | 请求格式或字段无效。 |
403 | 浏览器来源校验未通过。 |
413 | 请求体超出 4,096 字节。 |
415 | 需要 application/json 请求体。 |
405 | 请求方法不受支持。 |
500 | 账户服务暂时不可用。 |
503 | 此部署未配置该控制台服务。 |
401 | 控制台会话缺失、过期或无效。 |
使用细节
- 账户写请求来自站点同源页面。跨站请求由服务器拒绝。
- JSON 请求体最多 4,096 字节。