更新授权用户的资料¶
PATCH /api/v5/user
用户调用此接口,进行更新授权用户的资料操作.
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口不允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
access_token |
query | string | 是 | 用户授权码 |
Request Body:
请求体为 JSON 对象,用于更新授权用户的资料,所有字段均为可选。
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"avatar": {
"description": "头像",
"type": "string"
},
"nickname": {
"description": "用户昵称",
"type": "string"
},
"company": {
"description": "公司",
"type": "string"
},
"description": {
"description": "个人简介",
"type": "string"
},
"email": {
"description": "个人邮箱(需要通过认证处理)",
"type": "string"
},
"github_account": {
"description": "Github账号",
"type": "string"
},
"website": {
"description": "个人网站",
"type": "string"
},
"location": {
"description": "所在地",
"type": "string"
}
}
}
响应参数¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
avatar |
string | 是 | — | 头像 |
nickname |
string | 是 | — | 用户昵称 |
company |
string | 是 | — | 公司 |
description |
string | 是 | — | 个人简介 |
email |
string | 是 | — | 个人邮箱(需要通过认证处理) |
github_account |
string | 是 | — | Github账号 |
website |
string | 是 | — | 个人网站 |
location |
string | 是 | — | 所在地 |
id |
string | 是 | — | 用户ID |
login |
string | 是 | — | 登录名 |
失败响应¶
只有
200/成功响应是不够的:调用方需要知道失败长什么样才能写错误处理。
400 参数错误
401 未认证
错误字段名以后端实际返回为准。
HTTP 响应状态码¶
| 状态码 | 说明 |
|---|---|
200 |
成功(OK) |
400 |
参数错误或请求无法解析 |
401 |
需要认证(Requires authentication) |
403 |
禁止访问(Forbidden) |
404 |
请求路径不存在 |
405 |
请求方法不支持 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
请求示例¶
参数说明¶
<token>替换为你的 AtomGit 用户访问令牌。
cURL¶
curl -X PATCH 'https://api.atomgit.com/api/v5/user?access_token=<token>' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
"avatar": "https://api.atomgit.com/avatar/octocat.png",
"nickname": "octocat",
"company": "AtomGit",
"description": "开发者",
"email": "octocat@example.com",
"github_account": "octocat",
"website": "https://api.atomgit.com",
"location": "北京"
}'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch("https://api.atomgit.com/api/v5/user?access_token=<YOUR-TOKEN>", {
method: "PATCH",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
},
body: JSON.stringify({
avatar: "https://api.atomgit.com/avatar/octocat.png",
nickname: "octocat",
company: "AtomGit",
description: "开发者",
email: "octocat@example.com",
github_account: "octocat",
website: "https://api.atomgit.com",
location: "北京",
}),
});
if (!response.ok) {
throw new Error(`请求失败: ${response.status}`);
}
const data = await response.json();
console.log(data);
Python¶
import requests
resp = requests.patch(
"https://api.atomgit.com/api/v5/user",
params={"access_token": "<YOUR-TOKEN>"},
json={
"avatar": "https://api.atomgit.com/avatar/octocat.png",
"nickname": "octocat",
"company": "AtomGit",
"description": "开发者",
"email": "octocat@example.com",
"github_account": "octocat",
"website": "https://api.atomgit.com",
"location": "北京",
},
headers={
"Accept": "application/json",
},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
{
"avatar": "https://api.atomgit.com/avatar/28579840.png",
"nickname": "虞宇",
"company": "velit fugiat et labore qui",
"description": "铁情置。书活法建如压火。风海步省机厂。叫至道想报结。按后个段立省活。",
"email": "",
"github_account": "esse elit officia fugiat ad",
"website": "incididunt enim est",
"location": "in magna laboris Excepteur",
"id": "6638af02bbeee41d0fe74c35",
"login": "malongge5"
}
错误码¶
| 错误码 | 说明 |
|---|---|
401 |
未认证或凭证无效(缺少/无效的访问凭证) |
400 |
参数错误或请求无法解析 |
404 |
请求路径不存在 |
405 |
请求方法不支持 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc