列出指定用户的关注列表¶
GET /api/v5/users/{username}/following
列出指定用户所关注的用户列表,返回用户基础信息对象数组;结果按 page 与 per_page 分页。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
username |
path | string | 是 | 用户名(username/login) |
page |
query | integer | 否 | 当前页码,必须大于 0;默认 1 |
per_page |
query | integer | 否 | 每页的数量,必须大于 0 且不超过 100;默认 30 |
响应参数¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
avatar_url |
string | 是 | 是 | 头像地址 |
events_url |
string | 否 | 是 | 动态列表 API 地址,当前接口未返回 |
followers_url |
string | 是 | 是 | 粉丝列表 API 地址 |
following_url |
string | 否 | 是 | 关注列表 API 地址,仅当对象类型为 User 时返回 |
gists_url |
string | 否 | 是 | 代码片段 API 地址,当前接口未返回 |
html_url |
string | 是 | 是 | 用户或组织的页面地址 |
id |
string | 是 | 是 | 用户或组织的标识 |
object_id |
string | 是 | 是 | 用户对象标识 |
login |
string | 是 | 是 | 用户名或组织路径 |
member_role |
string | 否 | 是 | 成员角色,当前接口未返回 |
name |
string | 是 | 是 | 用户昵称或组织名称 |
organizations_url |
string | 否 | 是 | 所属组织列表 API 地址,当前接口未返回 |
received_events_url |
string | 否 | 是 | 接收动态列表 API 地址,当前接口未返回 |
remark |
string | 否 | 是 | 企业备注名,当前接口未返回 |
repos_url |
string | 否 | 是 | 仓库列表 API 地址,当前接口未返回 |
starred_url |
string | 否 | 是 | 收藏仓库列表 API 地址,当前接口未返回 |
subscriptions_url |
string | 否 | 是 | 订阅列表 API 地址,当前接口未返回 |
type |
string | 是 | 否 | 对象类型:User 表示用户,Organization 表示组织 |
url |
string | 是 | 是 | 用户或组织的详情 API 地址 |
Note: 响应体为上述对象组成的数组,数组元素既可能是用户(type 为 User),也可能是组织(type 为 Organization);组织元素不返回 following_url。
失败响应¶
除成功响应外,该接口在认证失败、参数非法、用户不存在或触发限流时会返回对应的错误状态。
400 参数错误
401 未认证
404 用户不存在或信息隐藏
Note: 当目标用户开启了个人信息隐藏且请求方不是该用户本人时,接口返回 404。
HTTP 响应状态码¶
| 状态码 | 说明 |
|---|---|
200 |
成功(OK) |
400 |
参数错误(Bad Request) |
401 |
需要认证或凭证无效(Unauthorized) |
403 |
禁止访问(Forbidden) |
404 |
用户不存在或信息隐藏(Not Found) |
429 |
请求过于频繁(Too Many Requests) |
500 |
系统内部错误(Internal Server Error) |
请求示例¶
参数说明¶
<username> 替换为目标用户的用户名(username/login);<token> 替换为你的 AtomGit 用户访问令牌。该接口允许匿名访问,也可携带令牌调用。
cURL¶
curl -X GET 'https://api.atomgit.com/api/v5/users/<username>/following?page=1&per_page=30' \
-H 'Authorization: Bearer <token>' \
-H 'Accept: application/json'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch(
"https://api.atomgit.com/api/v5/users/<username>/following?page=1&per_page=30",
{
headers: {
"Accept": "application/json",
"Authorization": "Bearer <YOUR-TOKEN>",
},
},
);
if (!response.ok) {
throw new Error(`请求失败: ${response.status}`);
}
const data = await response.json();
console.log(data);
Python¶
import requests
resp = requests.get(
"https://api.atomgit.com/api/v5/users/<username>/following",
params={"page": 1, "per_page": 30},
headers={
"Accept": "application/json",
"Authorization": "Bearer <YOUR-TOKEN>",
},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
[
{
"avatar_url": "https://api.atomgit.com/avatar/octocat.png",
"followers_url": "https://api.atomgit.com/api/v5/users/octocat/followers",
"following_url": "https://api.atomgit.com/api/v5/users/octocat/following",
"html_url": "https://api.atomgit.com/octocat",
"id": "496",
"object_id": "496",
"login": "octocat",
"name": "octocat",
"type": "User",
"url": "https://api.atomgit.com/api/v5/users/octocat"
},
{
"avatar_url": "https://api.atomgit.com/avatar/gitcode-org.png",
"followers_url": "https://api.atomgit.com/api/v5/orgs/gitcode-org/followers",
"html_url": "https://api.atomgit.com/gitcode-org",
"id": "137117",
"object_id": "137117",
"login": "gitcode-org",
"name": "AtomGit 组织",
"type": "Organization",
"url": "https://api.atomgit.com/api/v5/orgs/gitcode-org"
}
]
错误码¶
| 错误码 | 说明 |
|---|---|
400 |
参数错误或请求无法解析(如 page / per_page 非法) |
401 |
未认证或凭证无效(缺少/无效的访问凭证) |
403 |
禁止访问 |
404 |
用户不存在,或该用户开启了个人信息隐藏 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc