{"meta":{"title":"用户的 REST API 终结点","intro":"使用 REST API 获取有关经过身份验证的用户的公共和私人信息。","product":"REST API","breadcrumbs":[{"href":"/zh/rest","title":"REST API"},{"href":"/zh/rest/users","title":"用户"},{"href":"/zh/rest/users/users","title":"用户"}],"documentType":"article"},"body":"# 用户的 REST API 终结点\n\n使用 REST API 获取有关经过身份验证的用户的公共和私人信息。\n\n\n> [!NOTE]\n> Most endpoints use `Authorization: Bearer <YOUR-TOKEN>` and `Accept: application/vnd.github+json` headers, plus `X-GitHub-Api-Version: 2026-03-10`. Curl examples below omit these standard headers for brevity.\n\n\n## Get the authenticated user\n\n```\nGET /user\n```\n\nOAuth app tokens and personal access tokens (classic) need the user scope in order for the response to include private profile information.\n\n\n\n### HTTP response status codes\n\n\n- **200** - OK\n\n\n- **304** - Not modified\n\n\n- **401** - Requires authentication\n\n\n- **403** - Forbidden\n\n\n\n\n### Code examples\n\n\n\n#### Example 1: Status Code 200\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/user\n```\n\n**Response schema (Status: 200):**\n\n* one of:\n  * **Private User**\n    * `login`: required, string\n    * `id`: required, integer, format: int64\n    * `user_view_type`: string\n    * `node_id`: required, string\n    * `avatar_url`: required, string, format: uri\n    * `gravatar_id`: required, string or null\n    * `url`: required, string, format: uri\n    * `html_url`: required, string, format: uri\n    * `followers_url`: required, string, format: uri\n    * `following_url`: required, string\n    * `gists_url`: required, string\n    * `starred_url`: required, string\n    * `subscriptions_url`: required, string, format: uri\n    * `organizations_url`: required, string, format: uri\n    * `repos_url`: required, string, format: uri\n    * `events_url`: required, string\n    * `received_events_url`: required, string, format: uri\n    * `type`: required, string\n    * `site_admin`: required, boolean\n    * `name`: required, string or null\n    * `company`: required, string or null\n    * `blog`: required, string or null\n    * `location`: required, string or null\n    * `email`: required, string or null, format: email\n    * `notification_email`: string or null, format: email\n    * `hireable`: required, boolean or null\n    * `bio`: required, string or null\n    * `twitter_username`: string or null\n    * `public_repos`: required, integer\n    * `public_gists`: required, integer\n    * `followers`: required, integer\n    * `following`: required, integer\n    * `created_at`: required, string, format: date-time\n    * `updated_at`: required, string, format: date-time\n    * `private_gists`: required, integer\n    * `total_private_repos`: required, integer\n    * `owned_private_repos`: required, integer\n    * `disk_usage`: required, integer\n    * `collaborators`: required, integer\n    * `two_factor_authentication`: required, boolean\n    * `plan`: object:\n      * `collaborators`: required, integer\n      * `name`: required, string\n      * `space`: required, integer\n      * `private_repos`: required, integer\n    * `business_plus`: boolean\n    * `ldap_dn`: string\n  * **Public User**\n    * `login`: required, string\n    * `id`: required, integer, format: int64\n    * `user_view_type`: string\n    * `node_id`: required, string\n    * `avatar_url`: required, string, format: uri\n    * `gravatar_id`: required, string or null\n    * `url`: required, string, format: uri\n    * `html_url`: required, string, format: uri\n    * `followers_url`: required, string, format: uri\n    * `following_url`: required, string\n    * `gists_url`: required, string\n    * `starred_url`: required, string\n    * `subscriptions_url`: required, string, format: uri\n    * `organizations_url`: required, string, format: uri\n    * `repos_url`: required, string, format: uri\n    * `events_url`: required, string\n    * `received_events_url`: required, string, format: uri\n    * `type`: required, string\n    * `site_admin`: required, boolean\n    * `name`: required, string or null\n    * `company`: required, string or null\n    * `blog`: required, string or null\n    * `location`: required, string or null\n    * `email`: required, string or null, format: email\n    * `notification_email`: string or null, format: email\n    * `hireable`: required, boolean or null\n    * `bio`: required, string or null\n    * `twitter_username`: string or null\n    * `public_repos`: required, integer\n    * `public_gists`: required, integer\n    * `followers`: required, integer\n    * `following`: required, integer\n    * `created_at`: required, string, format: date-time\n    * `updated_at`: required, string, format: date-time\n    * `plan`: object:\n      * `collaborators`: required, integer\n      * `name`: required, string\n      * `space`: required, integer\n      * `private_repos`: required, integer\n    * `private_gists`: integer\n    * `total_private_repos`: integer\n    * `owned_private_repos`: integer\n    * `disk_usage`: integer\n    * `collaborators`: integer\n\n\n\n#### Example 2: Status Code 200\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/user\n```\n\n**Response schema (Status: 200):**\n\n* one of:\n  * **Private User**\n    * `login`: required, string\n    * `id`: required, integer, format: int64\n    * `user_view_type`: string\n    * `node_id`: required, string\n    * `avatar_url`: required, string, format: uri\n    * `gravatar_id`: required, string or null\n    * `url`: required, string, format: uri\n    * `html_url`: required, string, format: uri\n    * `followers_url`: required, string, format: uri\n    * `following_url`: required, string\n    * `gists_url`: required, string\n    * `starred_url`: required, string\n    * `subscriptions_url`: required, string, format: uri\n    * `organizations_url`: required, string, format: uri\n    * `repos_url`: required, string, format: uri\n    * `events_url`: required, string\n    * `received_events_url`: required, string, format: uri\n    * `type`: required, string\n    * `site_admin`: required, boolean\n    * `name`: required, string or null\n    * `company`: required, string or null\n    * `blog`: required, string or null\n    * `location`: required, string or null\n    * `email`: required, string or null, format: email\n    * `notification_email`: string or null, format: email\n    * `hireable`: required, boolean or null\n    * `bio`: required, string or null\n    * `twitter_username`: string or null\n    * `public_repos`: required, integer\n    * `public_gists`: required, integer\n    * `followers`: required, integer\n    * `following`: required, integer\n    * `created_at`: required, string, format: date-time\n    * `updated_at`: required, string, format: date-time\n    * `private_gists`: required, integer\n    * `total_private_repos`: required, integer\n    * `owned_private_repos`: required, integer\n    * `disk_usage`: required, integer\n    * `collaborators`: required, integer\n    * `two_factor_authentication`: required, boolean\n    * `plan`: object:\n      * `collaborators`: required, integer\n      * `name`: required, string\n      * `space`: required, integer\n      * `private_repos`: required, integer\n    * `business_plus`: boolean\n    * `ldap_dn`: string\n  * **Public User**\n    * `login`: required, string\n    * `id`: required, integer, format: int64\n    * `user_view_type`: string\n    * `node_id`: required, string\n    * `avatar_url`: required, string, format: uri\n    * `gravatar_id`: required, string or null\n    * `url`: required, string, format: uri\n    * `html_url`: required, string, format: uri\n    * `followers_url`: required, string, format: uri\n    * `following_url`: required, string\n    * `gists_url`: required, string\n    * `starred_url`: required, string\n    * `subscriptions_url`: required, string, format: uri\n    * `organizations_url`: required, string, format: uri\n    * `repos_url`: required, string, format: uri\n    * `events_url`: required, string\n    * `received_events_url`: required, string, format: uri\n    * `type`: required, string\n    * `site_admin`: required, boolean\n    * `name`: required, string or null\n    * `company`: required, string or null\n    * `blog`: required, string or null\n    * `location`: required, string or null\n    * `email`: required, string or null, format: email\n    * `notification_email`: string or null, format: email\n    * `hireable`: required, boolean or null\n    * `bio`: required, string or null\n    * `twitter_username`: string or null\n    * `public_repos`: required, integer\n    * `public_gists`: required, integer\n    * `followers`: required, integer\n    * `following`: required, integer\n    * `created_at`: required, string, format: date-time\n    * `updated_at`: required, string, format: date-time\n    * `plan`: object:\n      * `collaborators`: required, integer\n      * `name`: required, string\n      * `space`: required, integer\n      * `private_repos`: required, integer\n    * `private_gists`: integer\n    * `total_private_repos`: integer\n    * `owned_private_repos`: integer\n    * `disk_usage`: integer\n    * `collaborators`: integer\n\n\n\n\n\n## Update the authenticated user\n\n```\nPATCH /user\n```\n\nNote: If your email is set to private and you send an email parameter as part of this request to update your profile, your privacy settings are still enforced: the email address will not be displayed on your public profile or via the API.\n\n\n### Parameters\n\n\n#### Headers\n\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n\n\n\n\n#### Body parameters\n\n- **`name`** (string)\n  The new name of the user.\n\n- **`email`** (string)\n  The publicly visible email address of the user.\n\n- **`blog`** (string)\n  The new blog URL of the user.\n\n- **`twitter_username`** (string or null)\n  The new Twitter username of the user.\n\n- **`company`** (string)\n  The new company of the user.\n\n- **`location`** (string)\n  The new location of the user.\n\n- **`hireable`** (boolean)\n  The new hiring availability of the user.\n\n- **`bio`** (string)\n  The new short biography of the user.\n\n\n\n\n\n### HTTP response status codes\n\n\n- **200** - OK\n\n\n- **304** - Not modified\n\n\n- **401** - Requires authentication\n\n\n- **403** - Forbidden\n\n\n- **404** - Resource not found\n\n\n- **422** - Validation failed, or the endpoint has been spammed.\n\n\n\n\n### Code examples\n\n\n\n#### Example of updating blog and name\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X PATCH \\\n  https://api.github.com/user \\\n  -d '{\n  \"blog\": \"https://github.com/blog\",\n  \"name\": \"monalisa octocat\"\n}'\n```\n\n**Response schema (Status: 200):**\n\n* `login`: required, string\n* `id`: required, integer, format: int64\n* `user_view_type`: string\n* `node_id`: required, string\n* `avatar_url`: required, string, format: uri\n* `gravatar_id`: required, string or null\n* `url`: required, string, format: uri\n* `html_url`: required, string, format: uri\n* `followers_url`: required, string, format: uri\n* `following_url`: required, string\n* `gists_url`: required, string\n* `starred_url`: required, string\n* `subscriptions_url`: required, string, format: uri\n* `organizations_url`: required, string, format: uri\n* `repos_url`: required, string, format: uri\n* `events_url`: required, string\n* `received_events_url`: required, string, format: uri\n* `type`: required, string\n* `site_admin`: required, boolean\n* `name`: required, string or null\n* `company`: required, string or null\n* `blog`: required, string or null\n* `location`: required, string or null\n* `email`: required, string or null, format: email\n* `notification_email`: string or null, format: email\n* `hireable`: required, boolean or null\n* `bio`: required, string or null\n* `twitter_username`: string or null\n* `public_repos`: required, integer\n* `public_gists`: required, integer\n* `followers`: required, integer\n* `following`: required, integer\n* `created_at`: required, string, format: date-time\n* `updated_at`: required, string, format: date-time\n* `private_gists`: required, integer\n* `total_private_repos`: required, integer\n* `owned_private_repos`: required, integer\n* `disk_usage`: required, integer\n* `collaborators`: required, integer\n* `two_factor_authentication`: required, boolean\n* `plan`: object:\n  * `collaborators`: required, integer\n  * `name`: required, string\n  * `space`: required, integer\n  * `private_repos`: required, integer\n* `business_plus`: boolean\n* `ldap_dn`: string\n\n\n\n\n\n## Get a user using their ID\n\n```\nGET /user/{account_id}\n```\n\nProvides publicly available information about someone with a GitHub account. This method takes their durable user ID instead of their login, which can change over time.\nIf you are requesting information about an Enterprise Managed User, or a GitHub App bot that is installed in an organization that uses Enterprise Managed Users, your requests must be authenticated as a user or GitHub App that has access to the organization to view that account's information. If you are not authorized, the request will return a 404 Not Found status.\nThe email key in the following response is the publicly visible email address from your GitHub profile page. When setting up your profile, you can select a primary email address to be public which provides an email entry for this endpoint. If you do not set a public email address for email, then it will have a value of null. You only see publicly visible email addresses when authenticated with GitHub. For more information, see Authentication.\nThe Emails API enables you to list all of your email addresses, and toggle a primary email to be visible publicly. For more information, see Emails API.\n\n\n### Parameters\n\n\n#### Headers\n\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n\n\n#### Path and query parameters\n\n- **`account_id`** (integer) (required)\n  account_id parameter\n\n\n\n\n\n\n### HTTP response status codes\n\n\n- **200** - OK\n\n\n- **404** - Resource not found\n\n\n\n\n### Code examples\n\n\n\n#### Example 1: Status Code 200\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/user/ACCOUNT_ID\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [Get the authenticated user](#get-the-authenticated-user).\n\n\n\n#### Example 2: Status Code 200\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/user/ACCOUNT_ID\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [Get the authenticated user](#get-the-authenticated-user).\n\n\n\n\n\n## List users\n\n```\nGET /users\n```\n\nLists all users, in the order that they signed up on GitHub. This list includes personal user accounts and organization accounts.\nNote: Pagination is powered exclusively by the since parameter. Use the Link header to get the URL for the next page of users.\n\n\n### Parameters\n\n\n#### Headers\n\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n\n\n#### Path and query parameters\n\n- **`since`** (integer)\n  A user ID. Only return users with an ID greater than this ID.\n\n- **`per_page`** (integer)\n  The number of results per page (max 100). For more information, see \"Using pagination in the REST API.\"\n  Default: `30`\n\n\n\n\n\n\n### HTTP response status codes\n\n\n- **200** - OK\n\n\n- **304** - Not modified\n\n\n\n\n### Code examples\n\n\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/users\n```\n\n**Response schema (Status: 200):**\n\nArray of `Simple User`:\n  * `name`: string or null\n  * `email`: string or null\n  * `login`: required, string\n  * `id`: required, integer, format: int64\n  * `node_id`: required, string\n  * `avatar_url`: required, string, format: uri\n  * `gravatar_id`: required, string or null\n  * `url`: required, string, format: uri\n  * `html_url`: required, string, format: uri\n  * `followers_url`: required, string, format: uri\n  * `following_url`: required, string\n  * `gists_url`: required, string\n  * `starred_url`: required, string\n  * `subscriptions_url`: required, string, format: uri\n  * `organizations_url`: required, string, format: uri\n  * `repos_url`: required, string, format: uri\n  * `events_url`: required, string\n  * `received_events_url`: required, string, format: uri\n  * `type`: required, string\n  * `site_admin`: required, boolean\n  * `starred_at`: string\n  * `user_view_type`: string\n\n\n\n\n\n## Get a user\n\n```\nGET /users/{username}\n```\n\nProvides publicly available information about someone with a GitHub account.\nIf you are requesting information about an Enterprise Managed User, or a GitHub App bot that is installed in an organization that uses Enterprise Managed Users, your requests must be authenticated as a user or GitHub App that has access to the organization to view that account's information. If you are not authorized, the request will return a 404 Not Found status.\nThe email key in the following response is the publicly visible email address from your GitHub profile page. When setting up your profile, you can select a primary email address to be public which provides an email entry for this endpoint. If you do not set a public email address for email, then it will have a value of null. You only see publicly visible email addresses when authenticated with GitHub. For more information, see Authentication.\nThe Emails API enables you to list all of your email addresses, and toggle a primary email to be visible publicly. For more information, see Emails API.\n\n\n### Parameters\n\n\n#### Headers\n\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n\n\n#### Path and query parameters\n\n- **`username`** (string) (required)\n  The handle for the GitHub user account.\n\n\n\n\n\n\n### HTTP response status codes\n\n\n- **200** - OK\n\n\n- **404** - Resource not found\n\n\n\n\n### Code examples\n\n\n\n#### Example 1: Status Code 200\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/users/USERNAME\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [Get the authenticated user](#get-the-authenticated-user).\n\n\n\n#### Example 2: Status Code 200\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/users/USERNAME\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [Get the authenticated user](#get-the-authenticated-user).\n\n\n\n\n\n## Get contextual information for a user\n\n```\nGET /users/{username}/hovercard\n```\n\nProvides hovercard information. You can find out more about someone in relation to their pull requests, issues, repositories, and organizations.\nThe subject_type and subject_id parameters provide context for the person's hovercard, which returns more information than without the parameters. For example, if you wanted to find out more about octocat who owns the Spoon-Knife repository, you would use a subject_type value of repository and a subject_id value of 1300192 (the ID of the Spoon-Knife repository).\nOAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.\n\n\n### Parameters\n\n\n#### Headers\n\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n\n\n#### Path and query parameters\n\n- **`username`** (string) (required)\n  The handle for the GitHub user account.\n\n- **`subject_type`** (string)\n  Identifies which additional information you'd like to receive about the person's hovercard. Can be organization, repository, issue, pull_request. Required when using subject_id.\n  Can be one of: `organization`, `repository`, `issue`, `pull_request`\n\n- **`subject_id`** (string)\n  Uses the ID for the subject_type you specified. Required when using subject_type.\n\n\n\n\n\n\n### HTTP response status codes\n\n\n- **200** - OK\n\n\n- **404** - Resource not found\n\n\n- **422** - Validation failed, or the endpoint has been spammed.\n\n\n\n\n### Code examples\n\n\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/users/USERNAME/hovercard\n```\n\n**Response schema (Status: 200):**\n\n* `contexts`: required, array of objects:\n  * `message`: required, string\n  * `octicon`: required, string"}