用户的 REST API 端点
使用 REST API 获取有关已认证用户的公开和私有信息。
获取已认证用户
OAuth 应用令牌和个人访问令牌(经典)需要 user
范围,以便响应包含私有个人资料信息。
“获取已认证用户”的细粒度访问令牌
此端点适用于以下细粒度令牌类型:
细粒度令牌不需要任何权限。
“获取已认证用户”的 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
包含公开和私有个人资料信息的响应
状态: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, "name": "monalisa octocat", "company": "GitHub", "blog": "https://github.com/blog", "location": "San Francisco", "email": "octocat@github.com", "hireable": false, "bio": "There once was...", "twitter_username": "monatheoctocat", "public_repos": 2, "public_gists": 1, "followers": 20, "following": 0, "created_at": "2008-01-14T04:33:35Z", "updated_at": "2008-01-14T04:33:35Z", "private_gists": 81, "total_private_repos": 100, "owned_private_repos": 100, "disk_usage": 10000, "collaborators": 8, "two_factor_authentication": true, "plan": { "name": "Medium", "space": 400, "private_repos": 20, "collaborators": 0 } }
更新已认证用户
注意:如果您的电子邮件设置为私有,并且您在更新个人资料的请求中发送了 email
参数,则您的隐私设置仍然有效:电子邮件地址不会显示在您的公开个人资料或通过 API 中。
“更新已认证用户”的细粒度访问令牌
此端点适用于以下细粒度令牌类型:
细粒度令牌必须具有以下权限集
- “个人资料”用户权限(写入)
“更新已认证用户”的参数
名称、类型、描述 |
---|
accept 字符串建议设置为 |
名称、类型、描述 |
---|
name 字符串用户的新的名称。 |
email 字符串用户的公开可见的电子邮件地址。 |
blog 字符串用户的新的博客 URL。 |
twitter_username 字符串或 null用户的新的 Twitter 用户名。 |
company 字符串用户的新的公司。 |
location 字符串用户的新的位置。 |
hireable 布尔值用户的新的招聘可用性。 |
bio 字符串用户的新的简短个人简介。 |
“更新已认证用户”的 HTTP 响应状态代码
状态代码 | 描述 |
---|---|
200 | OK |
304 | 未修改 |
401 | 需要身份验证 |
403 | 禁止 |
404 | 资源未找到 |
422 | 验证失败或端点已被垃圾邮件发送。 |
“更新已认证用户”的代码示例
请求示例
curl -L \ -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/user \ -d '{"blog":"https://github.com/blog","name":"monalisa octocat"}'
响应
状态: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, "name": "monalisa octocat", "company": "GitHub", "blog": "https://github.com/blog", "location": "San Francisco", "email": "octocat@github.com", "hireable": false, "bio": "There once was...", "twitter_username": "monatheoctocat", "public_repos": 2, "public_gists": 1, "followers": 20, "following": 0, "created_at": "2008-01-14T04:33:35Z", "updated_at": "2008-01-14T04:33:35Z", "private_gists": 81, "total_private_repos": 100, "owned_private_repos": 100, "disk_usage": 10000, "collaborators": 8, "two_factor_authentication": true, "plan": { "name": "Medium", "space": 400, "private_repos": 20, "collaborators": 0 } }
使用用户 ID 获取用户
提供有关具有 GitHub 帐户的某人的公开可用信息。此方法使用其持久的用户 ID
而不是其 login
,因为 login
可能会随着时间的推移而发生变化。
以下响应中的 email
密钥是您 GitHub 个人资料页面上的公开可见的电子邮件地址。在设置个人资料时,您可以选择一个主要电子邮件地址作为“公开”,这将为此端点提供电子邮件条目。如果您未为 email
设置公开电子邮件地址,则其值为 null
。仅当使用 GitHub 进行身份验证时,您才能看到公开可见的电子邮件地址。有关更多信息,请参阅 身份验证。
电子邮件 API 使您能够列出所有电子邮件地址,并切换主要电子邮件以公开可见。有关更多信息,请参阅“电子邮件 API”。
“使用用户 ID 获取用户”的参数
名称、类型、描述 |
---|
accept 字符串建议设置为 |
名称、类型、描述 |
---|
account_id 整数 必需account_id 参数 |
“使用用户 ID 获取用户”的 HTTP 响应状态代码
状态代码 | 描述 |
---|---|
200 | OK |
404 | 资源未找到 |
“使用用户 ID 获取用户”的代码示例
请求示例
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/ACCOUNT_ID
默认响应
状态: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, "name": "monalisa octocat", "company": "GitHub", "blog": "https://github.com/blog", "location": "San Francisco", "email": "octocat@github.com", "hireable": false, "bio": "There once was...", "twitter_username": "monatheoctocat", "public_repos": 2, "public_gists": 1, "followers": 20, "following": 0, "created_at": "2008-01-14T04:33:35Z", "updated_at": "2008-01-14T04:33:35Z" }
列出用户
按用户在 GitHub 上注册的顺序列出所有用户。此列表包括个人用户帐户和组织帐户。
注意:分页完全由 since
参数提供支持。使用 Link 标头 获取用户下一页的 URL。
“列出用户”的细粒度访问令牌
此端点适用于以下细粒度令牌类型:
细粒度令牌不需要任何权限。
如果仅请求公共资源,则无需身份验证即可使用此端点。
“列出用户”的参数
名称、类型、描述 |
---|
accept 字符串建议设置为 |
名称、类型、描述 |
---|
since 整数用户 ID。仅返回 ID 大于此 ID 的用户。 |
per_page 整数每页的结果数(最大 100)。有关更多信息,请参阅“在 REST API 中使用分页”。 默认: |
“列出用户”的 HTTP 响应状态代码
状态代码 | 描述 |
---|---|
200 | OK |
304 | 未修改 |
“列出用户”的代码示例
请求示例
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
响应
状态: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 账户的用户的公开信息。
以下响应中的 email
密钥是您 GitHub 个人资料页面上的公开可见的电子邮件地址。在设置个人资料时,您可以选择一个主要电子邮件地址作为“公开”,这将为此端点提供电子邮件条目。如果您未为 email
设置公开电子邮件地址,则其值为 null
。仅当使用 GitHub 进行身份验证时,您才能看到公开可见的电子邮件地址。有关更多信息,请参阅 身份验证。
电子邮件 API 使您能够列出所有电子邮件地址,并切换主要电子邮件以公开可见。有关更多信息,请参阅“电子邮件 API”。
"获取用户信息"的参数
名称、类型、描述 |
---|
accept 字符串建议设置为 |
名称、类型、描述 |
---|
username 字符串 必填GitHub 用户账户的用户名。 |
"获取用户信息"的 HTTP 响应状态码
状态代码 | 描述 |
---|---|
200 | OK |
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/users/USERNAME
默认响应
状态: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, "name": "monalisa octocat", "company": "GitHub", "blog": "https://github.com/blog", "location": "San Francisco", "email": "octocat@github.com", "hireable": false, "bio": "There once was...", "twitter_username": "monatheoctocat", "public_repos": 2, "public_gists": 1, "followers": 20, "following": 0, "created_at": "2008-01-14T04:33:35Z", "updated_at": "2008-01-14T04:33:35Z" }
获取用户的上下文信息
提供悬停卡片信息。您可以了解有关用户与其拉取请求、问题、仓库和组织相关的信息。
subject_type
和 subject_id
参数为用户的悬停卡片提供上下文,返回比没有参数时更多的信息。例如,如果您想了解更多关于拥有 Spoon-Knife
仓库的 octocat
的信息,您可以使用 subject_type
值 repository
和 subject_id
值 1300192
(Spoon-Knife
仓库的 ID)。
OAuth 应用令牌和个人访问令牌(经典)需要 repo
范围才能使用此端点。
"获取用户的上下文信息"的细粒度访问令牌
此端点不适用于 GitHub 应用用户访问令牌、GitHub 应用安装访问令牌或细粒度个人访问令牌。
"获取用户的上下文信息"的参数
名称、类型、描述 |
---|
accept 字符串建议设置为 |
名称、类型、描述 |
---|
username 字符串 必填GitHub 用户账户的用户名。 |
名称、类型、描述 |
---|
subject_type 字符串标识您想接收的有关用户悬停卡片的其他信息。可以是 可以是以下之一: |
subject_id 字符串使用您指定的 |
"获取用户的上下文信息"的 HTTP 响应状态码
状态代码 | 描述 |
---|---|
200 | OK |
404 | 资源未找到 |
422 | 验证失败或端点已被垃圾邮件发送。 |
"获取用户的上下文信息"的代码示例
请求示例
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/hovercard
响应