用于加星的 REST API 端点
使用 REST API 为仓库添加书签。
关于加星
您可以使用 REST API 为仓库加星(书签)。加星显示在仓库旁边,以显示大致的兴趣程度。加星不会影响通知或活动提要。有关更多信息,请参阅“使用加星保存仓库”。
加星与关注
2012 年 8 月,我们更改了关注在 GitHub 上的工作方式。一些 API 客户端应用程序可能仍在使用原始的“关注者”端点来访问此数据。您现在应该使用“加星”端点(如下所述)。有关更多信息,请参阅“关注的 REST API 端点”和变更日志帖子。
在 REST API 的响应中,watchers
、watchers_count
和 stargazers_count
对应于已为仓库加星的用户数量,而 subscribers_count
对应于关注者数量。
列出加星者
“列出加星者”的细粒度访问令牌
此端点适用于以下细粒度令牌类型
细粒度令牌必须具有以下权限集
- “元数据”仓库权限(读取)
如果仅请求公共资源,则无需身份验证或上述权限即可使用此端点。
“列出加星者”的参数
名称、类型、描述 |
---|
accept string 建议设置为 |
名称、类型、描述 |
---|
owner string 必需仓库的帐户所有者。名称不区分大小写。 |
repo string 必需仓库名称,不包含 |
名称、类型、描述 |
---|
per_page 整数 每页结果数(最大 100)。有关更多信息,请参阅 "在 REST API 中使用分页”。 默认: |
page 整数 要获取的结果页码。有关更多信息,请参阅 "在 REST API 中使用分页”。 默认: |
“列出 Stargazers” 的 HTTP 响应状态码
状态码 | 描述 |
---|---|
200 | OK |
422 | 验证失败或端点已被垃圾邮件攻击。 |
“列出 Stargazers” 的代码示例
请求示例
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/stargazers
默认响应
状态: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 } ]
列出已认证用户收藏的仓库
用于“列出已认证用户收藏的仓库”的细粒度访问令牌
此端点适用于以下细粒度令牌类型
细粒度令牌必须具有以下权限集
- “收藏”用户权限(读取)
如果仅请求公共资源,则无需身份验证或上述权限即可使用此端点。
用于“列出已认证用户收藏的仓库”的参数
名称、类型、描述 |
---|
accept string 建议设置为 |
名称、类型、描述 |
---|
sort string 用于排序结果的属性。 默认: 可以是以下之一: |
direction string 排序结果的方向。 默认: 可以是以下之一: |
per_page 整数 每页结果数(最大 100)。有关更多信息,请参阅 "在 REST API 中使用分页”。 默认: |
page 整数 要获取的结果页码。有关更多信息,请参阅 "在 REST API 中使用分页”。 默认: |
用于“列出已认证用户收藏的仓库”的 HTTP 响应状态码
状态码 | 描述 |
---|---|
200 | OK |
304 | 未修改 |
401 | 需要身份验证 |
403 | 禁止 |
用于“列出已认证用户收藏的仓库”的代码示例
请求示例
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/starred
默认响应
状态: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": true,
"topics": [
"octocat",
"atom",
"electron",
"api"
],
"has_issues": true,
"has_projects": true,
"has_wiki": true,
"has_pages": false,
"has_downloads": true,
"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
},
"allow_rebase_merge": true,
"template_repository": null,
"temp_clone_token": "ABTLWHOULUVAXGTRYU7OC2876QJ2O",
"allow_squash_merge": true,
"allow_auto_merge": false,
"delete_branch_on_merge": true,
"allow_merge_commit": true,
"subscribers_count": 42,
"network_count": 0,
"license": {
"key": "mit",
"name": "MIT License",
"url": "https://api.github.com/licenses/mit",
"spdx_id": "MIT",
"node_id": "MDc6TGljZW5zZW1pdA==",
"html_url": "https://github.com/licenses/mit"
},
"forks": 1,
"open_issues": 1,
"watchers": 1
}
]
检查认证用户是否已收藏某个仓库
认证用户是否已收藏该仓库。
用于 "检查认证用户是否已收藏仓库" 的细粒度访问令牌
此端点适用于以下细粒度令牌类型
细粒度令牌必须具有以下权限集
- “收藏”用户权限(读取)
用于 "检查认证用户是否已收藏仓库" 的参数
名称、类型、描述 |
---|
accept string 建议设置为 |
名称、类型、描述 |
---|
owner string 必需仓库的帐户所有者。名称不区分大小写。 |
repo string 必需仓库名称,不包含 |
用于 "检查认证用户是否已收藏仓库" 的 HTTP 响应状态码
状态码 | 描述 |
---|---|
204 | 如果该仓库被您收藏,则返回响应 |
304 | 未修改 |
401 | 需要身份验证 |
403 | 禁止 |
404 | 如果该仓库未被您收藏,则返回 "未找到" |
用于 "检查认证用户是否已收藏仓库" 的代码示例
请求示例
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/starred/OWNER/REPO
如果该仓库被您收藏,则返回响应
状态: 204
为认证用户收藏仓库
请注意,您需要将 Content-Length
设置为零才能调用此端点。有关更多信息,请参阅 "HTTP 方法。"。
用于 "为认证用户收藏仓库" 的细粒度访问令牌
此端点适用于以下细粒度令牌类型
细粒度令牌必须具有以下权限集
- "收藏" 用户权限 (写入)
用于 "为认证用户收藏仓库" 的参数
名称、类型、描述 |
---|
accept string 建议设置为 |
名称、类型、描述 |
---|
owner string 必需仓库的帐户所有者。名称不区分大小写。 |
repo string 必需仓库名称,不包含 |
用于 "为认证用户收藏仓库" 的 HTTP 响应状态码
状态码 | 描述 |
---|---|
204 | 无内容 |
304 | 未修改 |
401 | 需要身份验证 |
403 | 禁止 |
404 | 资源未找到 |
用于 "为认证用户收藏仓库" 的代码示例
请求示例
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/user/starred/OWNER/REPO
响应
状态: 204
为认证用户取消收藏之前已收藏的仓库
取消收藏认证用户之前已收藏的仓库。
用于 "为认证用户取消收藏仓库" 的细粒度访问令牌
此端点适用于以下细粒度令牌类型
细粒度令牌必须具有以下权限集
- "收藏" 用户权限 (写入)
用于 "为认证用户取消收藏仓库" 的参数
名称、类型、描述 |
---|
accept string 建议设置为 |
名称、类型、描述 |
---|
owner string 必需仓库的帐户所有者。名称不区分大小写。 |
repo string 必需仓库名称,不包含 |
用于 "为认证用户取消收藏仓库" 的 HTTP 响应状态码
状态码 | 描述 |
---|---|
204 | 无内容 |
304 | 未修改 |
401 | 需要身份验证 |
403 | 禁止 |
404 | 资源未找到 |
用于 "为认证用户取消收藏仓库" 的代码示例
请求示例
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/user/starred/OWNER/REPO
响应
状态: 204
列出用户加星的仓库
用于“列出用户加星的仓库”的细粒度访问令牌
此端点适用于以下细粒度令牌类型
细粒度令牌必须具有以下权限集
- “收藏”用户权限(读取)
如果仅请求公共资源,则无需身份验证或上述权限即可使用此端点。
用于“列出用户加星的仓库”的参数
名称、类型、描述 |
---|
accept string 建议设置为 |
名称、类型、描述 |
---|
username 字符串 必需GitHub 用户帐户的句柄。 |
名称、类型、描述 |
---|
sort string 用于排序结果的属性。 默认: 可以是以下之一: |
direction string 排序结果的方向。 默认: 可以是以下之一: |
per_page 整数 每页结果数(最大 100)。有关更多信息,请参阅 "在 REST API 中使用分页”。 默认: |
page 整数 要获取的结果页码。有关更多信息,请参阅 "在 REST API 中使用分页”。 默认: |
用于“列出用户加星的仓库”的 HTTP 响应状态代码
状态码 | 描述 |
---|---|
200 | OK |
用于“列出用户加星的仓库”的代码示例
请求示例
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/starred
默认响应
状态: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": true,
"topics": [
"octocat",
"atom",
"electron",
"api"
],
"has_issues": true,
"has_projects": true,
"has_wiki": true,
"has_pages": false,
"has_downloads": true,
"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
},
"allow_rebase_merge": true,
"template_repository": null,
"temp_clone_token": "ABTLWHOULUVAXGTRYU7OC2876QJ2O",
"allow_squash_merge": true,
"allow_auto_merge": false,
"delete_branch_on_merge": true,
"allow_merge_commit": true,
"subscribers_count": 42,
"network_count": 0,
"license": {
"key": "mit",
"name": "MIT License",
"url": "https://api.github.com/licenses/mit",
"spdx_id": "MIT",
"node_id": "MDc6TGljZW5zZW1pdA==",
"html_url": "https://github.com/licenses/mit"
},
"forks": 1,
"open_issues": 1,
"watchers": 1
}
]