跳转至

获取用户信息

GET /api/v5/users/{username}

根据用户名(username)获取指定用户的信息。

访问令牌支持说明

  • AtomGit 用户访问令牌(AtomGit user access tokens)

是否允许匿名访问

此接口允许匿名访问

请求参数

参数名 位置 类型 必填 说明
username path string 是 用户名(username)

响应参数

字段 类型 必返 可为空 说明
avatar_url string 是 否 头像 URL
followers_url string 是 是 关注者列表 URL
html_url string 是 否 用户主页 URL
id string 是 否 用户 ID
login string 是 否 登录名
name string 是 否 用户名
type string 是 否 用户类型,如 User
url string 是 否 用户 API URL
bio string 是 是 个人简介
blog string 是 是 个人博客地址
company string 是 是 所属公司
email string 是 是 电子邮箱
followers integer 是 是 关注者数量
following integer 是 是 正在关注的人数
top_languages string[] 是 是 常用语言列表

失败响应

该接口无业务失败响应。

HTTP 响应状态码

状态码 说明
200 成功(OK)
401 需要认证(Requires authentication)
403 禁止访问(Forbidden)
404 用户不存在(Not found)

请求示例

参数说明

本接口允许匿名访问,也可携带 AtomGit 用户访问令牌。username 为路径参数,替换为目标用户的用户名。

<username> 替换为目标用户名(username)。

cURL

curl -X GET 'https://api.atomgit.com/api/v5/users/<username>' \
  -H 'Accept: application/json'

JavaScript

// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch("https://api.atomgit.com/api/v5/users/<username>", {
  headers: {
    "Accept": "application/json",
  },
});

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>",
    headers={
        "Accept": "application/json",
    },
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

响应示例

状态码: 200

{
  "avatar_url": "https://api.atomgit.com/avatars/octocat.png",
  "followers_url": "https://api.atomgit.com/api/v5/users/octocat/followers",
  "html_url": "https://api.atomgit.com/octocat",
  "id": "650d67fbae6d795139b49b41",
  "login": "octocat",
  "name": "Octocat",
  "type": "User",
  "url": "https://api.atomgit.com/api/v5/octocat",
  "bio": "A passionate developer.",
  "blog": "https://api.atomgit.com/blog/octocat",
  "company": "AtomGit",
  "email": "octocat@atomgit.com",
  "followers": 20,
  "following": 6,
  "top_languages": ["Java", "Python"]
}

错误码

错误码 说明
401 未认证或凭证无效(缺少/无效的访问凭证)
400 参数错误或请求无法解析
404 请求路径不存在
405 请求方法不支持
429 请求过于频繁,触发限流
500 系统内部错误

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc