跳转至

获取用户个人动态

GET /api/v5/users/{username}/events

用户调用此接口获取用户个人动态(按日期分组的事件列表)。

访问令牌支持说明

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

是否允许匿名访问

此接口不允许匿名访问

请求参数

参数名 位置 类型 必填 说明
username path string 是 用户名(username/login),如 dengmengmian
access_token query string 是 用户授权码
year query string 否 事件创建的年份(yyyy),如 2024
next query string 否 下一页起始时间(游标),如 2024-09-05T13:48:47.370Z

响应参数

字段 类型 必返 可为空 说明
events object 是 是 按日期分组的事件列表;键为事件日期(如 2024-08-27),值为事件对象数组
next string 否 是 下一页起始时间(游标),用于翻页

events.<date>[] 事件对象

字段 类型 必返 可为空 说明
action integer 是 是 动作类型编码
action_name string 是 是 动作名称,如 pushed to
author object 是 是 动态作者信息
author_id integer 是 是 作者 ID
author_username string 是 是 作者用户名
created_at string 是 是 动态创建时间(ISO 8601),如 2024-08-27T10:34:05.093Z
project object 是 是 关联项目信息
project_id integer 是 是 项目 ID
project_name string 是 是 项目名称,如 mactribe/midsommarcartoon
push_data object 否 是 推送数据,动态类型为推送时返回
_links object 否 是 相关链接

author 对象

字段 类型 必返 可为空 说明
author.id integer 是 是 作者 ID
author.iam_id string 是 是 IAM 账号 ID
author.username string 是 是 用户名
author.state string 是 是 账号状态,如 active
author.avatar_url string 是 是 头像地址
author.email string 是 是 邮箱
author.name string 是 是 姓名
author.name_cn string 是 是 中文名
author.web_url string 是 是 个人主页地址

project 对象

字段 类型 必返 可为空 说明
project.main_repository_language string[] 否 是 项目主要语言列表
project.star_count integer 是 是 Star 数量
project.forks_count integer 是 是 Fork 数量
project.develop_mode string 是 是 开发模式,如 normal
project.stared boolean 是 是 当前用户是否已 Star 该项目

push_data 对象

字段 类型 必返 可为空 说明
push_data.commit_count integer 否 是 提交数量
push_data.action string 否 是 动作,如 pushed
push_data.ref_type string 否 是 引用类型,如 branch
push_data.commit_from string 否 是 起始提交 SHA
push_data.commit_to string 否 是 目标提交 SHA
push_data.ref string 否 是 分支/引用名,如 main
push_data.commit_title string 否 是 提交标题
字段 类型 必返 可为空 说明
_links.project string 否 是 项目地址
_links.action_type string 否 是 动作类型链接

失败响应

400 参数错误

{
  "error": "invalid_request",
  "message": "参数 username 不能为空",
  "field": "username"
}

401 未认证

{
  "error": "unauthorized",
  "message": "缺少或无效的访问令牌"
}

Note: 实际错误字段名以后端返回为准。

HTTP 响应状态码

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

请求示例

参数说明

<username> 替换为用户名(username/login,如 dengmengmian); <token> 替换为你的 AtomGit 用户访问令牌; <year>(可选)替换为要查询的事件年份,如 2024。

cURL

curl -X GET 'https://api.atomgit.com/api/v5/users/<username>/events?access_token=<token>&year=2024' \
  -H 'Accept: application/json'

JavaScript

// 原生 fetch (Node.js 18+ / 浏览器)
const username = "dengmengmian";
const token = "<YOUR-TOKEN>";
const url = `https://api.atomgit.com/api/v5/users/${username}/events?access_token=${token}&year=2024`;

const response = await fetch(url, {
  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>/events",
    params={
        "access_token": "<YOUR-TOKEN>",
        "year": "2024",
    },
    headers={"Accept": "application/json"},
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

响应示例

状态码: 200

{
  "events": {
    "2024-08-27": [
      {
        "action": 5,
        "action_name": "pushed to",
        "author": {
          "id": 704,
          "iam_id": "5c340cab034d455992541f00f9936fb4",
          "username": "dengmengmian",
          "state": "active",
          "avatar_url": "https://gitcode-img.obs.cn-south-1.myhuaweicloud.com:443/fa/fe/f32a9fecc53e890afbd48fd098b0f6c5f20f062581400c76c85e5baab3f0d5b2.png",
          "email": "",
          "name": "dengmengmian",
          "name_cn": "dengmengmian",
          "web_url": "https://api.atomgit.com/dengmengmian"
        },
        "author_id": 704,
        "author_username": "dengmengmian",
        "created_at": "2024-08-27T10:34:05.093Z",
        "project": {
          "main_repository_language": ["Java", "Python"],
          "star_count": 0,
          "forks_count": 0,
          "develop_mode": "normal",
          "stared": false
        },
        "project_id": 507167,
        "project_name": "mactribe/midsommarcartoon",
        "push_data": {
          "commit_count": 1,
          "action": "pushed",
          "ref_type": "branch",
          "commit_from": "2ce472fec073f77804c3480ccf128219a6172e54",
          "commit_to": "14b742fe434797fb073ba536804011f735f2f430",
          "ref": "main",
          "commit_title": "文件title"
        },
        "_links": {
          "project": "https://api.atomgit.com/mactribe/midsommarcartoon",
          "action_type": ""
        }
      }
    ]
  },
  "next": "2024-08-01T10:10:40.370Z"
}

错误码

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

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