登录账号

验证邮箱和密码,建立或替换当前控制台会话。

POST/api/account/login
认证
公开,无需登录。
成功状态
200

请求参数

参数类型位置必填说明
emailstringbody是有效的邮箱地址,去空白后最多 254 个字符。
passwordstringbody是当前密码,1–128 个字符。

请求示例

cURL
curl -i -X POST 'https://social2api.com/api/account/login' \
  -H 'Content-Type: application/json' \
  --data-binary '{
  "email": "reader@example.com",
  "password": "<current password>"
}'
Python
from urllib.error import HTTPError
from urllib.request import Request, urlopen

request = Request(
    "https://social2api.com/api/account/login",
    method="POST",
    headers={
        "Content-Type": "application/json",
    },
    data="{\"email\":\"reader@example.com\",\"password\":\"<current password>\"}".encode("utf-8"),
)
send = urlopen
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/login", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "email": "reader@example.com",
    "password": "<current password>"
  }),
});
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": "账户服务暂不可用,请稍后重试。"
}
字段类型说明
accountobject当前操作涉及的账号。
account.idstring账号 ID。
account.emailstring规范化的邮箱地址。
account.namestring显示名。
account.createdAtISO 8601 date-time账号创建时间。
account.emailVerifiedboolean邮箱是否通过验证。
account.hasPasswordboolean该账号是否已设置密码。
account.preferencesobject已存储的账号偏好。

错误状态

HTTP原因与处理
400请求格式或字段无效。
403浏览器来源校验未通过。
413请求体超出 4,096 字节。
415需要 application/json 请求体。
405请求方法不受支持。
500账户服务暂时不可用。
503此部署未配置该控制台服务。
401凭据无效或已过期。
429尝试次数过多。根据 Retry-After 的秒数再试。

使用细节

  • 账户写请求来自站点同源页面。跨站请求由服务器拒绝。
  • JSON 请求体最多 4,096 字节。
  • 登录成功后响应以 Set-Cookie 建立或更新会话。