跳至主要内容
REST API 现在已版本化。 有关更多信息,请参阅 "关于 API 版本控制"。

用于观看的 REST API 端点

使用 REST API 订阅仓库活动通知。

关于观看

您可以使用 REST API 订阅仓库活动通知。要改为收藏仓库,请参阅 "用于收藏的 REST API 端点"。

观看与收藏

2012 年 8 月,我们 更改了观看在 GitHub 上的工作方式。一些 API 客户端应用程序可能仍在使用原始的“观察者”端点来访问此数据。您现在应该改用“收藏”端点。有关更多信息,请参阅 "用于收藏的 REST API 端点" 和 变更日志文章

在 REST API 的响应中,subscribers_count 对应于观察者数量,而 watcherswatchers_countstargazers_count 对应于收藏仓库的用户数量。

列出观察者

列出观看指定仓库的人员。

用于“列出观察者”的细粒度访问令牌

此端点与以下细粒度令牌类型一起使用

细粒度令牌必须具有以下权限集

  • "元数据" 仓库权限(读取)

如果只请求公共资源,则可以使用此端点,无需身份验证或上述权限。

"列出观察者" 的参数

标头
名称、类型、描述
accept 字符串

建议设置为 application/vnd.github+json

路径参数
名称、类型、描述
owner 字符串 必需

仓库的帐户所有者。名称不区分大小写。

repo 字符串 必需

仓库的名称,不包含 .git 扩展名。名称不区分大小写。

查询参数
名称、类型、描述
per_page 整数

每页结果数(最大 100)。有关更多信息,请参阅 "在 REST API 中使用分页。"。

默认: 30

page 整数

要获取的结果的页码。有关更多信息,请参阅 "在 REST API 中使用分页。"。

默认: 1

"列出观察者" 的 HTTP 响应状态代码

状态代码描述
200

OK

"列出观察者" 的代码示例

请求示例

get/repos/{owner}/{repo}/subscribers
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/subscribers

响应

状态:200
[ { "login": "octocat", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "", "url": "https://api.github.com/users/octocat", "html_url": "https://github.com/octocat", "followers_url": "https://api.github.com/users/octocat/followers", "following_url": "https://api.github.com/users/octocat/following{/other_user}", "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", "organizations_url": "https://api.github.com/users/octocat/orgs", "repos_url": "https://api.github.com/users/octocat/repos", "events_url": "https://api.github.com/users/octocat/events{/privacy}", "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false } ]

获取仓库订阅

获取有关经过身份验证的用户是否订阅了存储库的信息。

用于“获取存储库订阅”的细粒度访问令牌

此端点不适用于 GitHub App 用户访问令牌、GitHub App 安装访问令牌或细粒度个人访问令牌。

“获取存储库订阅”的参数

标头
名称、类型、描述
accept 字符串

建议设置为 application/vnd.github+json

路径参数
名称、类型、描述
owner 字符串 必需

仓库的帐户所有者。名称不区分大小写。

repo 字符串 必需

仓库的名称,不包含 .git 扩展名。名称不区分大小写。

“获取存储库订阅”的 HTTP 响应状态代码

状态代码描述
200

如果您订阅了存储库

403

禁止

404

如果您未订阅存储库,则为“未找到”

“获取存储库订阅”的代码示例

请求示例

get/repos/{owner}/{repo}/subscription
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/subscription

如果您订阅了存储库

状态:200
{ "subscribed": true, "ignored": false, "reason": null, "created_at": "2012-10-06T21:34:12Z", "url": "https://api.github.com/repos/octocat/example/subscription", "repository_url": "https://api.github.com/repos/octocat/example" }

设置存储库订阅

如果您想关注某个存储库,请将 subscribed 设置为 true。如果您想忽略存储库内的通知,请将 ignored 设置为 true。如果您想停止关注某个存储库,请完全删除存储库的订阅

用于“设置存储库订阅”的细粒度访问令牌

此端点不适用于 GitHub App 用户访问令牌、GitHub App 安装访问令牌或细粒度个人访问令牌。

“设置存储库订阅”的参数

标头
名称、类型、描述
accept 字符串

建议设置为 application/vnd.github+json

路径参数
名称、类型、描述
owner 字符串 必需

仓库的帐户所有者。名称不区分大小写。

repo 字符串 必需

仓库的名称,不包含 .git 扩展名。名称不区分大小写。

主体参数
名称、类型、描述
subscribed boolean

确定是否应从该存储库接收通知。

ignored boolean

确定是否应阻止来自该存储库的所有通知。

“设置存储库订阅”的 HTTP 响应状态代码

状态代码描述
200

OK

“设置存储库订阅”的代码示例

请求示例

put/repos/{owner}/{repo}/subscription
curl -L \ -X PUT \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/subscription \ -d '{"subscribed":true,"ignored":false}'

响应

状态:200
{ "subscribed": true, "ignored": false, "reason": null, "created_at": "2012-10-06T21:34:12Z", "url": "https://api.github.com/repos/octocat/example/subscription", "repository_url": "https://api.github.com/repos/octocat/example" }

删除存储库订阅

此端点仅应用于停止关注存储库。要控制是否希望从存储库接收通知,请手动设置存储库的订阅

用于“删除存储库订阅”的细粒度访问令牌

此端点不适用于 GitHub App 用户访问令牌、GitHub App 安装访问令牌或细粒度个人访问令牌。

“删除存储库订阅”的参数

标头
名称、类型、描述
accept 字符串

建议设置为 application/vnd.github+json

路径参数
名称、类型、描述
owner 字符串 必需

仓库的帐户所有者。名称不区分大小写。

repo 字符串 必需

仓库的名称,不包含 .git 扩展名。名称不区分大小写。

“删除存储库订阅”的 HTTP 响应状态代码

状态代码描述
204

无内容

“删除存储库订阅”的代码示例

请求示例

delete/repos/{owner}/{repo}/subscription
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/subscription

响应

状态:204

列出经过身份验证的用户关注的存储库

列出经过身份验证的用户正在关注的仓库。

用于“列出经过身份验证的用户正在关注的仓库”的细粒度访问令牌

此端点与以下细粒度令牌类型一起使用

细粒度令牌必须具有以下权限集

  • “关注”用户权限(读取)

如果只请求公共资源,则可以使用此端点,无需身份验证或上述权限。

“列出经过身份验证的用户正在关注的仓库”的参数

标头
名称、类型、描述
accept 字符串

建议设置为 application/vnd.github+json

查询参数
名称、类型、描述
per_page 整数

每页结果数(最大 100)。有关更多信息,请参阅 "在 REST API 中使用分页。"。

默认: 30

page 整数

要获取的结果的页码。有关更多信息,请参阅 "在 REST API 中使用分页。"。

默认: 1

“列出经过身份验证的用户正在关注的仓库”的 HTTP 响应状态代码

状态代码描述
200

OK

304

未修改

401

需要身份验证

403

禁止

“列出经过身份验证的用户正在关注的仓库”的代码示例

请求示例

get/user/subscriptions
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/user/subscriptions

响应

状态:200
[ { "id": 1296269, "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", "name": "Hello-World", "full_name": "octocat/Hello-World", "owner": { "login": "octocat", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "", "url": "https://api.github.com/users/octocat", "html_url": "https://github.com/octocat", "followers_url": "https://api.github.com/users/octocat/followers", "following_url": "https://api.github.com/users/octocat/following{/other_user}", "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", "organizations_url": "https://api.github.com/users/octocat/orgs", "repos_url": "https://api.github.com/users/octocat/repos", "events_url": "https://api.github.com/users/octocat/events{/privacy}", "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false }, "private": false, "html_url": "https://github.com/octocat/Hello-World", "description": "This your first repo!", "fork": false, "url": "https://api.github.com/repos/octocat/Hello-World", "archive_url": "https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}", "assignees_url": "https://api.github.com/repos/octocat/Hello-World/assignees{/user}", "blobs_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}", "branches_url": "https://api.github.com/repos/octocat/Hello-World/branches{/branch}", "collaborators_url": "https://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}", "comments_url": "https://api.github.com/repos/octocat/Hello-World/comments{/number}", "commits_url": "https://api.github.com/repos/octocat/Hello-World/commits{/sha}", "compare_url": "https://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}", "contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/{+path}", "contributors_url": "https://api.github.com/repos/octocat/Hello-World/contributors", "deployments_url": "https://api.github.com/repos/octocat/Hello-World/deployments", "downloads_url": "https://api.github.com/repos/octocat/Hello-World/downloads", "events_url": "https://api.github.com/repos/octocat/Hello-World/events", "forks_url": "https://api.github.com/repos/octocat/Hello-World/forks", "git_commits_url": "https://api.github.com/repos/octocat/Hello-World/git/commits{/sha}", "git_refs_url": "https://api.github.com/repos/octocat/Hello-World/git/refs{/sha}", "git_tags_url": "https://api.github.com/repos/octocat/Hello-World/git/tags{/sha}", "git_url": "git:github.com/octocat/Hello-World.git", "issue_comment_url": "https://api.github.com/repos/octocat/Hello-World/issues/comments{/number}", "issue_events_url": "https://api.github.com/repos/octocat/Hello-World/issues/events{/number}", "issues_url": "https://api.github.com/repos/octocat/Hello-World/issues{/number}", "keys_url": "https://api.github.com/repos/octocat/Hello-World/keys{/key_id}", "labels_url": "https://api.github.com/repos/octocat/Hello-World/labels{/name}", "languages_url": "https://api.github.com/repos/octocat/Hello-World/languages", "merges_url": "https://api.github.com/repos/octocat/Hello-World/merges", "milestones_url": "https://api.github.com/repos/octocat/Hello-World/milestones{/number}", "notifications_url": "https://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}", "pulls_url": "https://api.github.com/repos/octocat/Hello-World/pulls{/number}", "releases_url": "https://api.github.com/repos/octocat/Hello-World/releases{/id}", "ssh_url": "[email protected]:octocat/Hello-World.git", "stargazers_url": "https://api.github.com/repos/octocat/Hello-World/stargazers", "statuses_url": "https://api.github.com/repos/octocat/Hello-World/statuses/{sha}", "subscribers_url": "https://api.github.com/repos/octocat/Hello-World/subscribers", "subscription_url": "https://api.github.com/repos/octocat/Hello-World/subscription", "tags_url": "https://api.github.com/repos/octocat/Hello-World/tags", "teams_url": "https://api.github.com/repos/octocat/Hello-World/teams", "trees_url": "https://api.github.com/repos/octocat/Hello-World/git/trees{/sha}", "clone_url": "https://github.com/octocat/Hello-World.git", "mirror_url": "git:git.example.com/octocat/Hello-World", "hooks_url": "https://api.github.com/repos/octocat/Hello-World/hooks", "svn_url": "https://svn.github.com/octocat/Hello-World", "homepage": "https://github.com", "language": null, "forks_count": 9, "stargazers_count": 80, "watchers_count": 80, "size": 108, "default_branch": "master", "open_issues_count": 0, "is_template": false, "topics": [ "octocat", "atom", "electron", "api" ], "has_issues": true, "has_projects": true, "has_wiki": true, "has_pages": false, "has_downloads": true, "has_discussions": false, "archived": false, "disabled": false, "visibility": "public", "pushed_at": "2011-01-26T19:06:43Z", "created_at": "2011-01-26T19:01:12Z", "updated_at": "2011-01-26T19:14:43Z", "permissions": { "admin": false, "push": false, "pull": true }, "security_and_analysis": { "advanced_security": { "status": "enabled" }, "secret_scanning": { "status": "enabled" }, "secret_scanning_push_protection": { "status": "disabled" } } } ]

列出用户正在关注的仓库

列出用户正在关注的仓库。

用于“列出用户正在关注的仓库”的细粒度访问令牌

此端点与以下细粒度令牌类型一起使用

细粒度令牌必须具有以下权限集

  • “关注”用户权限(读取)

如果只请求公共资源,则可以使用此端点,无需身份验证或上述权限。

“列出用户正在关注的仓库”的参数

标头
名称、类型、描述
accept 字符串

建议设置为 application/vnd.github+json

路径参数
名称、类型、描述
username string 必需

GitHub 用户帐户的句柄。

查询参数
名称、类型、描述
per_page 整数

每页结果数(最大 100)。有关更多信息,请参阅 "在 REST API 中使用分页。"。

默认: 30

page 整数

要获取的结果的页码。有关更多信息,请参阅 "在 REST API 中使用分页。"。

默认: 1

“列出用户正在关注的仓库”的 HTTP 响应状态代码

状态代码描述
200

OK

“列出用户正在关注的仓库”的代码示例

请求示例

get/users/{username}/subscriptions
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/users/USERNAME/subscriptions

响应

状态:200
[ { "id": 1296269, "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", "name": "Hello-World", "full_name": "octocat/Hello-World", "owner": { "login": "octocat", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "", "url": "https://api.github.com/users/octocat", "html_url": "https://github.com/octocat", "followers_url": "https://api.github.com/users/octocat/followers", "following_url": "https://api.github.com/users/octocat/following{/other_user}", "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", "organizations_url": "https://api.github.com/users/octocat/orgs", "repos_url": "https://api.github.com/users/octocat/repos", "events_url": "https://api.github.com/users/octocat/events{/privacy}", "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false }, "private": false, "html_url": "https://github.com/octocat/Hello-World", "description": "This your first repo!", "fork": false, "url": "https://api.github.com/repos/octocat/Hello-World", "archive_url": "https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}", "assignees_url": "https://api.github.com/repos/octocat/Hello-World/assignees{/user}", "blobs_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}", "branches_url": "https://api.github.com/repos/octocat/Hello-World/branches{/branch}", "collaborators_url": "https://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}", "comments_url": "https://api.github.com/repos/octocat/Hello-World/comments{/number}", "commits_url": "https://api.github.com/repos/octocat/Hello-World/commits{/sha}", "compare_url": "https://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}", "contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/{+path}", "contributors_url": "https://api.github.com/repos/octocat/Hello-World/contributors", "deployments_url": "https://api.github.com/repos/octocat/Hello-World/deployments", "downloads_url": "https://api.github.com/repos/octocat/Hello-World/downloads", "events_url": "https://api.github.com/repos/octocat/Hello-World/events", "forks_url": "https://api.github.com/repos/octocat/Hello-World/forks", "git_commits_url": "https://api.github.com/repos/octocat/Hello-World/git/commits{/sha}", "git_refs_url": "https://api.github.com/repos/octocat/Hello-World/git/refs{/sha}", "git_tags_url": "https://api.github.com/repos/octocat/Hello-World/git/tags{/sha}", "git_url": "git:github.com/octocat/Hello-World.git", "issue_comment_url": "https://api.github.com/repos/octocat/Hello-World/issues/comments{/number}", "issue_events_url": "https://api.github.com/repos/octocat/Hello-World/issues/events{/number}", "issues_url": "https://api.github.com/repos/octocat/Hello-World/issues{/number}", "keys_url": "https://api.github.com/repos/octocat/Hello-World/keys{/key_id}", "labels_url": "https://api.github.com/repos/octocat/Hello-World/labels{/name}", "languages_url": "https://api.github.com/repos/octocat/Hello-World/languages", "merges_url": "https://api.github.com/repos/octocat/Hello-World/merges", "milestones_url": "https://api.github.com/repos/octocat/Hello-World/milestones{/number}", "notifications_url": "https://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}", "pulls_url": "https://api.github.com/repos/octocat/Hello-World/pulls{/number}", "releases_url": "https://api.github.com/repos/octocat/Hello-World/releases{/id}", "ssh_url": "[email protected]:octocat/Hello-World.git", "stargazers_url": "https://api.github.com/repos/octocat/Hello-World/stargazers", "statuses_url": "https://api.github.com/repos/octocat/Hello-World/statuses/{sha}", "subscribers_url": "https://api.github.com/repos/octocat/Hello-World/subscribers", "subscription_url": "https://api.github.com/repos/octocat/Hello-World/subscription", "tags_url": "https://api.github.com/repos/octocat/Hello-World/tags", "teams_url": "https://api.github.com/repos/octocat/Hello-World/teams", "trees_url": "https://api.github.com/repos/octocat/Hello-World/git/trees{/sha}", "clone_url": "https://github.com/octocat/Hello-World.git", "mirror_url": "git:git.example.com/octocat/Hello-World", "hooks_url": "https://api.github.com/repos/octocat/Hello-World/hooks", "svn_url": "https://svn.github.com/octocat/Hello-World", "homepage": "https://github.com", "language": null, "forks_count": 9, "stargazers_count": 80, "watchers_count": 80, "size": 108, "default_branch": "master", "open_issues_count": 0, "is_template": false, "topics": [ "octocat", "atom", "electron", "api" ], "has_issues": true, "has_projects": true, "has_wiki": true, "has_pages": false, "has_downloads": true, "has_discussions": false, "archived": false, "disabled": false, "visibility": "public", "pushed_at": "2011-01-26T19:06:43Z", "created_at": "2011-01-26T19:01:12Z", "updated_at": "2011-01-26T19:14:43Z", "permissions": { "admin": false, "push": false, "pull": true }, "security_and_analysis": { "advanced_security": { "status": "enabled" }, "secret_scanning": { "status": "enabled" }, "secret_scanning_push_protection": { "status": "disabled" } } } ]