跳至主要内容
REST API 现已版本化。 有关详细信息,请参阅“关于 API 版本控制”。

用于搜索的 REST API 端点

使用 REST API 在 GitHub 上搜索特定项目。

你可以使用 REST API 搜索你想要找到的特定项目。例如,你可以在存储库中找到用户或特定文件。你可以将它想象成在 Google 上执行搜索的方式。它的设计目的是帮助你找到你正在寻找的唯一结果(或你正在寻找的少数结果)。就像在 Google 上搜索一样,你有时希望看到几页搜索结果,以便找到最能满足你需求的项目。为了满足这一需求,GitHub REST API 为每次搜索提供多达 1,000 个结果

你可以使用查询缩小搜索范围。要详细了解搜索查询语法,请参阅“用于搜索的 REST API 端点”。

搜索结果排名

除非另提供其他排序选项作为查询参数,否则结果按最佳匹配降序排列。将多个因素结合起来,将最相关的项目提升到结果列表的顶部。

速率限制

REST API 对搜索有自定义速率限制。对于经过身份验证的请求,对于除“搜索代码”端点之外的所有搜索端点,每分钟最多可进行 30 次请求。“搜索代码”端点要求您进行身份验证,并限制您每分钟最多进行 10 次请求。对于未经身份验证的请求,速率限制允许您每分钟最多进行 10 次请求。

有关如何确定当前速率限制状态的信息,请参阅“速率限制”。

构建搜索查询

用于搜索的每个端点都使用 查询参数 在 GitHub 上执行搜索。有关包括端点和查询参数在内的示例,请参阅各个端点。

查询可以包含 GitHub 上支持的任何搜索限定符组合。搜索查询的格式为

SEARCH_KEYWORD_1 SEARCH_KEYWORD_N QUALIFIER_1 QUALIFIER_N

例如,如果您想搜索 defunkt 拥有的所有包含 README 文件中包含单词 GitHubOctocat存储库,则可以使用以下查询和搜索存储库端点

GitHub Octocat in:readme user:defunkt

注意:务必使用您语言的首选 HTML 编码器来构建您的查询字符串。例如

// JavaScript
const queryString = 'q=' + encodeURIComponent('GitHub Octocat in:readme user:defunkt');

有关可用限定符、其格式以及如何使用它们的示例的完整列表,请参阅“在 GitHub 上搜索”。有关如何使用运算符来匹配特定数量、日期或排除结果的信息,请参阅“了解搜索语法”。

查询长度限制

您不能使用

  • 长度超过 256 个字符(不包括运算符或限定符)的查询。
  • 具有超过五个 ANDORNOT 运算符的查询。

这些搜索查询将返回“验证失败”错误消息。

搜索范围限制

为了让 REST API 对每个人都保持快速,我们限制查询将搜索的存储库数量。REST API 将找到多达 4,000 个与您的筛选器匹配的存储库,并从这些存储库返回结果。

超时和不完整的结果

为了让 REST API 对每个人都保持快速,我们限制任何单个查询可以运行的时间。对于超出时间限制的查询,API 将返回在超时之前已找到的匹配项,并且响应将把 incomplete_results 属性设置为 true

达到超时并不一定意味着搜索结果不完整。可能已经找到了更多结果,但也可能没有。

访问错误或缺少搜索结果

您需要成功进行身份验证并能够访问搜索查询中的存储库,否则,您将看到带有“验证失败”消息的 422 不可处理的条目 错误。例如,如果您的查询包含 repo:user:org: 限定符,而这些限定符请求您在 GitHub 上登录时无法访问的资源,则您的搜索将失败。

当您的搜索查询请求多个资源时,响应将仅包含您有权访问的资源,并且不会提供列出未返回资源的错误消息。

例如,如果您的搜索查询搜索 octocat/testcodertocat/test 存储库,但您只能访问 octocat/test,则您的响应将显示 octocat/test 的搜索结果,而 codertocat/test 则没有任何内容。此行为模仿了 GitHub 上搜索的工作方式。

文本匹配元数据

在 GitHub 上,您可以在搜索结果中使用代码片段和高亮显示提供的上下文。用于搜索的端点返回其他元数据,允许您在显示搜索结果时突出显示匹配的搜索词。

请求可以选择在响应中接收这些文本片段,并且每个片段都附有数字偏移量,标识每个匹配搜索词的确切位置。

要在搜索结果中获取此元数据,请在 Accept 标头中指定 text-match 媒体类型。

application/vnd.github.text-match+json

当您提供 text-match 媒体类型时,您将在 JSON 有效负载中收到一个名为 text_matches 的额外键,该键提供有关搜索词在文本中的位置以及包含搜索词的 property 的信息。在 text_matches 数组中,每个对象都包含以下属性

名称说明
object_url包含与某个搜索词匹配的字符串属性的资源的 URL。
object_type在给定的 object_url 处存在的资源类型的名称。
propertyobject_url 处存在的资源的属性的名称。该属性是一个与某个搜索词匹配的字符串。(在从 object_url 返回的 JSON 中,fragment 的完整内容将在具有此名称的属性中找到。)
fragmentproperty 值的子集。这是与一个或多个搜索词匹配的文本片段。
matches存在于 fragment 中的一个或多个搜索词的数组。索引(即“偏移量”)相对于片段。(它们不是相对于 property完整内容。)

示例

使用 curl 命令和上述 示例问题搜索,我们的 API 请求将如下所示

curl -H 'Accept: application/vnd.github.text-match+json' \
'https://api.github.com/search/issues?q=windows+label:bug \
+language:python+state:open&sort=created&order=asc'

响应将为每个搜索结果包含一个 text_matches 数组。在下面的 JSON 中,text_matches 数组中有两个对象。

第一个文本匹配发生在问题的 body 属性中。我们看到问题正文中的一段文本片段。搜索词(windows)在该片段中出现两次,我们有每个出现的索引。

第二个文本匹配发生在问题的一个评论的 body 属性中。我们有该问题评论的 URL。当然,我们看到评论正文中的一段文本片段。搜索词(windows)在该片段中出现一次。

{
  "text_matches": [
    {
      "object_url": "https://api.github.com/repositories/215335/issues/132",
      "object_type": "Issue",
      "property": "body",
      "fragment": "comprehensive windows font I know of).\n\nIf we can find a commonly
      distributed windows font that supports them then no problem (we can use html
      font tags) but otherwise the '(21)' style is probably better.\n",
      "matches": [
        {
          "text": "windows",
          "indices": [
            14,
            21
          ]
        },
        {
          "text": "windows",
          "indices": [
            78,
            85
          ]
        }
      ]
    },
    {
      "object_url": "https://api.github.com/repositories/215335/issues/comments/25688",
      "object_type": "IssueComment",
      "property": "body",
      "fragment": " right after that are a bit broken IMHO :). I suppose we could
      have some hack that maxes out at whatever the font does...\n\nI'll check
      what the state of play is on Windows.\n",
      "matches": [
        {
          "text": "Windows",
          "indices": [
            163,
            170
          ]
        }
      ]
    }
  ]
}

搜索代码

在文件中搜索查询词。此方法每页最多返回 100 个结果

在搜索代码时,当您传递 text-match 媒体类型时,可以获取文件内容和文件路径字段的文本匹配元数据。有关如何接收高亮搜索结果的更多详细信息,请参阅 文本匹配元数据

例如,如果您想在 jQuery 存储库中找到 addClass 函数的定义,您的查询将如下所示

q=addClass+in:file+language:js+repo:jquery/jquery

此查询在文件的内容中搜索关键字 addClass。查询将搜索限制在 jquery/jquery 存储库中语言为 JavaScript 的文件。

代码搜索注意事项

由于代码搜索的复杂性,对搜索执行方式有一些限制

  • 只考虑默认分支。在大多数情况下,这将是master分支。
  • 只能搜索小于 384 KB 的文件。
  • 搜索源代码时,您必须始终至少包含一个搜索词。例如,搜索language:go无效,而amazing language:go有效。

此端点要求您进行身份验证,并且每分钟限制您进行 10 次请求。

“搜索代码”的细粒度访问令牌

此端点适用于以下细粒度令牌类型

细粒度令牌不需要任何权限。

如果仅请求公共资源,则无需身份验证即可使用此端点。

“搜索代码”的参数

标头
名称、类型、说明
accept string

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

查询参数
名称、类型、说明
q string Required

查询包含一个或多个搜索关键字和限定符。限定符允许您将搜索限制在 GitHub 的特定区域。REST API 支持与 GitHub Web 界面相同的限定符。要了解有关查询格式的更多信息,请参阅构建搜索查询。有关限定符的详细列表,请参阅“搜索代码”。

sort string

此字段已弃用。对查询结果进行排序。只能是indexed,它表示 GitHub 搜索基础架构最近对文件编制索引的时间。默认:最佳匹配

: indexed

order string

此字段已弃用。确定返回的第一个搜索结果是匹配数最高 (desc) 还是匹配数最低 (asc)。除非您提供sort,否则将忽略此参数。

默认: desc

可以是以下之一: desc, asc

per_page integer

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

默认: 30

page integer

要获取的结果的页码。有关详细信息,请参阅“在 REST API 中使用分页”。

默认: 1

“搜索代码”的 HTTP 响应状态代码

状态代码说明
200

正常

304

未修改

403

禁止

422

验证失败,或端点遭到垃圾邮件攻击。

503

服务不可用

“搜索代码”的代码示例

请求示例

get/search/code
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/search/code?q=Q"

响应

状态: 200
{ "total_count": 7, "incomplete_results": false, "items": [ { "name": "classes.js", "path": "src/attributes/classes.js", "sha": "d7212f9dee2dcc18f084d7df8f417b80846ded5a", "url": "https://api.github.com/repositories/167174/contents/src/attributes/classes.js?ref=825ac3773694e0cd23ee74895fd5aeb535b27da4", "git_url": "https://api.github.com/repositories/167174/git/blobs/d7212f9dee2dcc18f084d7df8f417b80846ded5a", "html_url": "https://github.com/jquery/jquery/blob/825ac3773694e0cd23ee74895fd5aeb535b27da4/src/attributes/classes.js", "repository": { "id": 167174, "node_id": "MDEwOlJlcG9zaXRvcnkxNjcxNzQ=", "name": "jquery", "full_name": "jquery/jquery", "owner": { "login": "jquery", "id": 70142, "node_id": "MDQ6VXNlcjcwMTQy", "avatar_url": "https://0.gravatar.com/avatar/6906f317a4733f4379b06c32229ef02f?d=https%3A%2F%2Fidenticons.github.com%2Ff426f04f2f9813718fb806b30e0093de.png", "gravatar_id": "", "url": "https://api.github.com/users/jquery", "html_url": "https://github.com/jquery", "followers_url": "https://api.github.com/users/jquery/followers", "following_url": "https://api.github.com/users/jquery/following{/other_user}", "gists_url": "https://api.github.com/users/jquery/gists{/gist_id}", "starred_url": "https://api.github.com/users/jquery/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jquery/subscriptions", "organizations_url": "https://api.github.com/users/jquery/orgs", "repos_url": "https://api.github.com/users/jquery/repos", "events_url": "https://api.github.com/users/jquery/events{/privacy}", "received_events_url": "https://api.github.com/users/jquery/received_events", "type": "Organization", "site_admin": false }, "private": false, "html_url": "https://github.com/jquery/jquery", "description": "jQuery JavaScript Library", "fork": false, "url": "https://api.github.com/repos/jquery/jquery", "forks_url": "https://api.github.com/repos/jquery/jquery/forks", "keys_url": "https://api.github.com/repos/jquery/jquery/keys{/key_id}", "collaborators_url": "https://api.github.com/repos/jquery/jquery/collaborators{/collaborator}", "teams_url": "https://api.github.com/repos/jquery/jquery/teams", "hooks_url": "https://api.github.com/repos/jquery/jquery/hooks", "issue_events_url": "https://api.github.com/repos/jquery/jquery/issues/events{/number}", "events_url": "https://api.github.com/repos/jquery/jquery/events", "assignees_url": "https://api.github.com/repos/jquery/jquery/assignees{/user}", "branches_url": "https://api.github.com/repos/jquery/jquery/branches{/branch}", "tags_url": "https://api.github.com/repos/jquery/jquery/tags", "blobs_url": "https://api.github.com/repos/jquery/jquery/git/blobs{/sha}", "git_tags_url": "https://api.github.com/repos/jquery/jquery/git/tags{/sha}", "git_refs_url": "https://api.github.com/repos/jquery/jquery/git/refs{/sha}", "trees_url": "https://api.github.com/repos/jquery/jquery/git/trees{/sha}", "statuses_url": "https://api.github.com/repos/jquery/jquery/statuses/{sha}", "languages_url": "https://api.github.com/repos/jquery/jquery/languages", "stargazers_url": "https://api.github.com/repos/jquery/jquery/stargazers", "contributors_url": "https://api.github.com/repos/jquery/jquery/contributors", "subscribers_url": "https://api.github.com/repos/jquery/jquery/subscribers", "subscription_url": "https://api.github.com/repos/jquery/jquery/subscription", "commits_url": "https://api.github.com/repos/jquery/jquery/commits{/sha}", "git_commits_url": "https://api.github.com/repos/jquery/jquery/git/commits{/sha}", "comments_url": "https://api.github.com/repos/jquery/jquery/comments{/number}", "issue_comment_url": "https://api.github.com/repos/jquery/jquery/issues/comments/{number}", "contents_url": "https://api.github.com/repos/jquery/jquery/contents/{+path}", "compare_url": "https://api.github.com/repos/jquery/jquery/compare/{base}...{head}", "merges_url": "https://api.github.com/repos/jquery/jquery/merges", "archive_url": "https://api.github.com/repos/jquery/jquery/{archive_format}{/ref}", "downloads_url": "https://api.github.com/repos/jquery/jquery/downloads", "issues_url": "https://api.github.com/repos/jquery/jquery/issues{/number}", "pulls_url": "https://api.github.com/repos/jquery/jquery/pulls{/number}", "milestones_url": "https://api.github.com/repos/jquery/jquery/milestones{/number}", "notifications_url": "https://api.github.com/repos/jquery/jquery/notifications{?since,all,participating}", "labels_url": "https://api.github.com/repos/jquery/jquery/labels{/name}", "deployments_url": "http://api.github.com/repos/octocat/Hello-World/deployments", "releases_url": "http://api.github.com/repos/octocat/Hello-World/releases{/id}" }, "score": 1 } ] }

搜索提交

通过默认分支(通常为 main)上的各种条件查找提交。此方法每页最多返回 100 个结果

在搜索提交时,当您提供 text-match 媒体类型时,可以获取 message 字段的文本匹配元数据。有关如何接收突出显示的搜索结果的更多详细信息,请参阅 文本匹配元数据

例如,如果您想在 octocat/Spoon-Knife 存储库中查找与 CSS 相关的提交。您的查询将类似于以下内容

q=repo:octocat/Spoon-Knife+css

“搜索提交”的细粒度访问令牌

此端点适用于以下细粒度令牌类型

细粒度令牌不需要任何权限。

如果仅请求公共资源,则无需身份验证即可使用此端点。

“搜索提交”的参数

标头
名称、类型、说明
accept string

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

查询参数
名称、类型、说明
q string Required

查询包含一个或多个搜索关键字和限定符。限定符允许你将搜索范围限制在 GitHub 的特定区域。REST API 支持与 GitHub 的 Web 界面相同的限定符。要了解有关查询格式的更多信息,请参阅 构建搜索查询。有关限定符的详细列表,请参阅“搜索提交”。

sort string

author-datecommitter-date 对查询结果进行排序。默认值:最佳匹配

可以为以下之一: author-date, committer-date

order string

确定返回的第一个搜索结果是匹配数最高(desc)还是匹配数最低(asc)。除非你提供 sort,否则将忽略此参数。

默认: desc

可以是以下之一: desc, asc

per_page integer

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

默认: 30

page integer

要获取的结果的页码。有关详细信息,请参阅“在 REST API 中使用分页”。

默认: 1

“搜索提交”的 HTTP 响应状态代码

状态代码说明
200

正常

304

未修改

“搜索提交”的代码示例

请求示例

get/search/commits
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/search/commits?q=Q"

响应

状态: 200
{ "total_count": 1, "incomplete_results": false, "items": [ { "url": "https://api.github.com/repos/octocat/Spoon-Knife/commits/bb4cc8d3b2e14b3af5df699876dd4ff3acd00b7f", "sha": "bb4cc8d3b2e14b3af5df699876dd4ff3acd00b7f", "html_url": "https://github.com/octocat/Spoon-Knife/commit/bb4cc8d3b2e14b3af5df699876dd4ff3acd00b7f", "comments_url": "https://api.github.com/repos/octocat/Spoon-Knife/commits/bb4cc8d3b2e14b3af5df699876dd4ff3acd00b7f/comments", "commit": { "url": "https://api.github.com/repos/octocat/Spoon-Knife/git/commits/bb4cc8d3b2e14b3af5df699876dd4ff3acd00b7f", "author": { "date": "2014-02-04T14:38:36-08:00", "name": "The Octocat", "email": "[email protected]" }, "committer": { "date": "2014-02-12T15:18:55-08:00", "name": "The Octocat", "email": "[email protected]" }, "message": "Create styles.css and updated README", "tree": { "url": "https://api.github.com/repos/octocat/Spoon-Knife/git/trees/a639e96f9038797fba6e0469f94a4b0cc459fa68", "sha": "a639e96f9038797fba6e0469f94a4b0cc459fa68" }, "comment_count": 8 }, "author": { "login": "octocat", "id": 583231, "node_id": "MDQ6VXNlcjU4MzIzMQ==", "avatar_url": "https://avatars.githubusercontent.com/u/583231?v=3", "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 }, "committer": {}, "parents": [ { "url": "https://api.github.com/repos/octocat/Spoon-Knife/commits/a30c19e3f13765a3b48829788bc1cb8b4e95cee4", "html_url": "https://github.com/octocat/Spoon-Knife/commit/a30c19e3f13765a3b48829788bc1cb8b4e95cee4", "sha": "a30c19e3f13765a3b48829788bc1cb8b4e95cee4" } ], "repository": { "id": 1300192, "node_id": "MDEwOlJlcG9zaXRvcnkxMzAwMTky", "name": "Spoon-Knife", "full_name": "octocat/Spoon-Knife", "owner": { "login": "octocat", "id": 583231, "node_id": "MDQ6VXNlcjU4MzIzMQ==", "avatar_url": "https://avatars.githubusercontent.com/u/583231?v=3", "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/Spoon-Knife", "description": "This repo is for demonstration purposes only.", "fork": false, "url": "https://api.github.com/repos/octocat/Spoon-Knife", "forks_url": "https://api.github.com/repos/octocat/Spoon-Knife/forks", "keys_url": "https://api.github.com/repos/octocat/Spoon-Knife/keys{/key_id}", "collaborators_url": "https://api.github.com/repos/octocat/Spoon-Knife/collaborators{/collaborator}", "teams_url": "https://api.github.com/repos/octocat/Spoon-Knife/teams", "hooks_url": "https://api.github.com/repos/octocat/Spoon-Knife/hooks", "issue_events_url": "https://api.github.com/repos/octocat/Spoon-Knife/issues/events{/number}", "events_url": "https://api.github.com/repos/octocat/Spoon-Knife/events", "assignees_url": "https://api.github.com/repos/octocat/Spoon-Knife/assignees{/user}", "branches_url": "https://api.github.com/repos/octocat/Spoon-Knife/branches{/branch}", "tags_url": "https://api.github.com/repos/octocat/Spoon-Knife/tags", "blobs_url": "https://api.github.com/repos/octocat/Spoon-Knife/git/blobs{/sha}", "git_tags_url": "https://api.github.com/repos/octocat/Spoon-Knife/git/tags{/sha}", "git_refs_url": "https://api.github.com/repos/octocat/Spoon-Knife/git/refs{/sha}", "trees_url": "https://api.github.com/repos/octocat/Spoon-Knife/git/trees{/sha}", "statuses_url": "https://api.github.com/repos/octocat/Spoon-Knife/statuses/{sha}", "languages_url": "https://api.github.com/repos/octocat/Spoon-Knife/languages", "stargazers_url": "https://api.github.com/repos/octocat/Spoon-Knife/stargazers", "contributors_url": "https://api.github.com/repos/octocat/Spoon-Knife/contributors", "subscribers_url": "https://api.github.com/repos/octocat/Spoon-Knife/subscribers", "subscription_url": "https://api.github.com/repos/octocat/Spoon-Knife/subscription", "commits_url": "https://api.github.com/repos/octocat/Spoon-Knife/commits{/sha}", "git_commits_url": "https://api.github.com/repos/octocat/Spoon-Knife/git/commits{/sha}", "comments_url": "https://api.github.com/repos/octocat/Spoon-Knife/comments{/number}", "issue_comment_url": "https://api.github.com/repos/octocat/Spoon-Knife/issues/comments{/number}", "contents_url": "https://api.github.com/repos/octocat/Spoon-Knife/contents/{+path}", "compare_url": "https://api.github.com/repos/octocat/Spoon-Knife/compare/{base}...{head}", "merges_url": "https://api.github.com/repos/octocat/Spoon-Knife/merges", "archive_url": "https://api.github.com/repos/octocat/Spoon-Knife/{archive_format}{/ref}", "downloads_url": "https://api.github.com/repos/octocat/Spoon-Knife/downloads", "issues_url": "https://api.github.com/repos/octocat/Spoon-Knife/issues{/number}", "pulls_url": "https://api.github.com/repos/octocat/Spoon-Knife/pulls{/number}", "milestones_url": "https://api.github.com/repos/octocat/Spoon-Knife/milestones{/number}", "notifications_url": "https://api.github.com/repos/octocat/Spoon-Knife/notifications{?since,all,participating}", "labels_url": "https://api.github.com/repos/octocat/Spoon-Knife/labels{/name}", "releases_url": "https://api.github.com/repos/octocat/Spoon-Knife/releases{/id}", "deployments_url": "https://api.github.com/repos/octocat/Spoon-Knife/deployments" }, "score": 1, "node_id": "MDQ6VXNlcjU4MzIzMQ==" } ] }

搜索问题和拉取请求

按状态和关键字查找问题。此方法每页返回多达 100 个结果

搜索问题时,当你传递 text-match 媒体类型时,你可以获取问题 标题、问题 正文 和问题 评论正文 字段的文本匹配元数据。有关如何接收高亮搜索结果的更多详细信息,请参阅 文本匹配元数据

例如,如果你想找到 Windows 上最旧的未解决 Python bug。你的查询可能如下所示。

q=windows+label:bug+language:python+state:open&sort=created&order=asc

此查询在标记为 bug 的任何未解决问题中搜索关键字 windows。搜索在主语言为 Python 的存储库中进行。结果按创建日期升序排列,这意味着最旧的问题首先出现在搜索结果中。

注意:对于使用用户访问令牌的 GitHub 应用发出的请求,你无法在单个查询中检索问题和拉取请求的组合。不包含 is:issueis:pull-request 限定符的请求将收到 HTTP 422 不可处理的实体 响应。若要获取问题和拉取请求的结果,你必须针对问题和拉取请求发送单独的查询。有关 is 限定符的更多信息,请参阅“仅搜索问题或拉取请求”。

“搜索问题和拉取请求”的细粒度访问令牌

此端点适用于以下细粒度令牌类型

细粒度令牌不需要任何权限。

如果仅请求公共资源,则无需身份验证即可使用此端点。

“搜索问题和拉取请求”的参数

标头
名称、类型、说明
accept string

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

查询参数
名称、类型、说明
q string Required

查询包含一个或多个搜索关键字和限定符。限定符允许你将搜索限制在 GitHub 的特定区域。REST API 支持与 GitHub Web 界面相同的限定符。若要详细了解查询的格式,请参阅 构建搜索查询。有关限定符的详细列表,请参阅“搜索问题和拉取请求”。

sort string

commentsreactionsreactions-+1reactions--1reactions-smilereactions-thinking_facereactions-heartreactions-tadainteractions 的数量对查询结果进行排序。你还可以按项目最近 createdupdated 的时间对结果进行排序,默认:最佳匹配

可以是以下之一: comments, reactions, reactions-+1, reactions--1, reactions-smile, reactions-thinking_face, reactions-heart, reactions-tada, interactions, created, updated

order string

确定返回的第一个搜索结果是匹配数最高(desc)还是匹配数最低(asc)。除非你提供 sort,否则将忽略此参数。

默认: desc

可以是以下之一: desc, asc

per_page integer

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

默认: 30

page integer

要获取的结果的页码。有关详细信息,请参阅“在 REST API 中使用分页”。

默认: 1

“搜索问题和拉取请求”的 HTTP 响应状态代码

状态代码说明
200

正常

304

未修改

403

禁止

422

验证失败,或端点遭到垃圾邮件攻击。

503

服务不可用

“搜索问题和拉取请求”的代码示例

请求示例

get/search/issues
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/search/issues?q=Q"

响应

状态: 200
{ "total_count": 280, "incomplete_results": false, "items": [ { "url": "https://api.github.com/repos/batterseapower/pinyin-toolkit/issues/132", "repository_url": "https://api.github.com/repos/batterseapower/pinyin-toolkit", "labels_url": "https://api.github.com/repos/batterseapower/pinyin-toolkit/issues/132/labels{/name}", "comments_url": "https://api.github.com/repos/batterseapower/pinyin-toolkit/issues/132/comments", "events_url": "https://api.github.com/repos/batterseapower/pinyin-toolkit/issues/132/events", "html_url": "https://github.com/batterseapower/pinyin-toolkit/issues/132", "id": 35802, "node_id": "MDU6SXNzdWUzNTgwMg==", "number": 132, "title": "Line Number Indexes Beyond 20 Not Displayed", "user": { "login": "Nick3C", "id": 90254, "node_id": "MDQ6VXNlcjkwMjU0", "avatar_url": "https://secure.gravatar.com/avatar/934442aadfe3b2f4630510de416c5718?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png", "gravatar_id": "", "url": "https://api.github.com/users/Nick3C", "html_url": "https://github.com/Nick3C", "followers_url": "https://api.github.com/users/Nick3C/followers", "following_url": "https://api.github.com/users/Nick3C/following{/other_user}", "gists_url": "https://api.github.com/users/Nick3C/gists{/gist_id}", "starred_url": "https://api.github.com/users/Nick3C/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Nick3C/subscriptions", "organizations_url": "https://api.github.com/users/Nick3C/orgs", "repos_url": "https://api.github.com/users/Nick3C/repos", "events_url": "https://api.github.com/users/Nick3C/events{/privacy}", "received_events_url": "https://api.github.com/users/Nick3C/received_events", "type": "User", "site_admin": true }, "labels": [ { "id": 4, "node_id": "MDU6TGFiZWw0", "url": "https://api.github.com/repos/batterseapower/pinyin-toolkit/labels/bug", "name": "bug", "color": "ff0000" } ], "state": "open", "assignee": null, "milestone": { "url": "https://api.github.com/repos/octocat/Hello-World/milestones/1", "html_url": "https://github.com/octocat/Hello-World/milestones/v1.0", "labels_url": "https://api.github.com/repos/octocat/Hello-World/milestones/1/labels", "id": 1002604, "node_id": "MDk6TWlsZXN0b25lMTAwMjYwNA==", "number": 1, "state": "open", "title": "v1.0", "description": "Tracking milestone for version 1.0", "creator": { "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 }, "open_issues": 4, "closed_issues": 8, "created_at": "2011-04-10T20:09:31Z", "updated_at": "2014-03-03T18:58:10Z", "closed_at": "2013-02-12T13:22:01Z", "due_on": "2012-10-09T23:39:01Z" }, "comments": 15, "created_at": "2009-07-12T20:10:41Z", "updated_at": "2009-07-19T09:23:43Z", "closed_at": null, "pull_request": { "url": "https://api/github.com/repos/octocat/Hello-World/pull/1347", "html_url": "https://github.com/octocat/Hello-World/pull/1347", "diff_url": "https://github.com/octocat/Hello-World/pull/1347.diff", "patch_url": "https://api.github.com/repos/octocat/Hello-World/pulls/1347" }, "body": "...", "score": 1, "locked": true, "author_association": "COLLABORATOR", "state_reason": "completed" } ] }

搜索标签

在名称或描述与搜索关键字匹配的存储库中查找标签。每页返回多达 100 个结果

搜索标签时,当你传递 text-match 媒体类型时,可以获取标签 名称描述 字段的文本匹配元数据。有关如何接收高亮搜索结果的更多详细信息,请参阅 文本匹配元数据

例如,如果你想在 linguist 存储库中查找与 bugdefectenhancement 匹配的标签。你的查询可能如下所示

q=bug+defect+enhancement&repository_id=64778136

与查询最匹配的标签首先出现在搜索结果中。

“搜索标签”的细粒度访问令牌

此端点适用于以下细粒度令牌类型

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

  • “元数据”存储库权限(读取)

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

“搜索标签”的参数

标头
名称、类型、说明
accept string

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

查询参数
名称、类型、说明
repository_id 整数 必需

存储库的 ID。

q string Required

搜索关键字。此端点不接受查询中的限定符。要了解有关查询格式的更多信息,请参阅 构建搜索查询

sort string

按标签 createdupdated 的时间对查询结果进行排序。默认值:最佳匹配

可以是以下之一: created, updated

order string

确定返回的第一个搜索结果是匹配数最高(desc)还是匹配数最低(asc)。除非你提供 sort,否则将忽略此参数。

默认: desc

可以是以下之一: desc, asc

per_page integer

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

默认: 30

page integer

要获取的结果的页码。有关详细信息,请参阅“在 REST API 中使用分页”。

默认: 1

“搜索标签”的 HTTP 响应状态代码

状态代码说明
200

正常

304

未修改

403

禁止

404

资源未找到

422

验证失败,或端点遭到垃圾邮件攻击。

“搜索标签”的代码示例

请求示例

get/search/labels
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/search/labels?repository_id=REPOSITORY_ID&q=Q"

响应

状态: 200
{ "total_count": 2, "incomplete_results": false, "items": [ { "id": 418327088, "node_id": "MDU6TGFiZWw0MTgzMjcwODg=", "url": "https://api.github.com/repos/octocat/linguist/labels/enhancement", "name": "enhancement", "color": "84b6eb", "default": true, "description": "New feature or request.", "score": 1 }, { "id": 418327086, "node_id": "MDU6TGFiZWw0MTgzMjcwODY=", "url": "https://api.github.com/repos/octocat/linguist/labels/bug", "name": "bug", "color": "ee0701", "default": true, "description": "Something isn't working.", "score": 1 } ] }

搜索存储库

通过各种条件查找存储库。此方法每页返回多达 100 个结果

搜索存储库时,传递 text-match 媒体类型时,可以获取 名称描述 字段的文本匹配元数据。有关如何接收高亮搜索结果的更多详细信息,请参阅 文本匹配元数据

例如,如果您想搜索用汇编代码编写的流行 Tetris 存储库,您的查询可能如下所示

q=tetris+language:assembly&sort=stars&order=desc

此查询搜索名称、描述或 README 中包含单词 tetris 的存储库。结果仅限于主要语言为汇编的存储库。结果按星级降序排列,以便最受欢迎的存储库首先出现在搜索结果中。

“搜索存储库”的细粒度访问令牌

此端点适用于以下细粒度令牌类型

细粒度令牌不需要任何权限。

如果仅请求公共资源,则无需身份验证即可使用此端点。

“搜索存储库”的参数

标头
名称、类型、说明
accept string

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

查询参数
名称、类型、说明
q string Required

查询包含一个或多个搜索关键字和限定符。限定符允许您将搜索限制在 GitHub 的特定区域。REST API 支持与 GitHub Web 界面相同的限定符。要了解有关查询格式的更多信息,请参阅 构建搜索查询。有关限定符的详细列表,请参阅“搜索存储库”。

sort string

starsforkshelp-wanted-issues 的数量或最近更新项目的时间对查询结果进行排序。默认值:最佳匹配

可以是以下之一:: stars, forks, help-wanted-issues, updated

order string

确定返回的第一个搜索结果是匹配数最高(desc)还是匹配数最低(asc)。除非你提供 sort,否则将忽略此参数。

默认: desc

可以是以下之一: desc, asc

per_page integer

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

默认: 30

page integer

要获取的结果的页码。有关详细信息,请参阅“在 REST API 中使用分页”。

默认: 1

“搜索存储库”的 HTTP 响应状态代码

状态代码说明
200

正常

304

未修改

422

验证失败,或端点遭到垃圾邮件攻击。

503

服务不可用

“搜索存储库”的代码示例

请求示例

get/search/repositories
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/search/repositories?q=Q"

响应

状态: 200
{ "total_count": 40, "incomplete_results": false, "items": [ { "id": 3081286, "node_id": "MDEwOlJlcG9zaXRvcnkzMDgxMjg2", "name": "Tetris", "full_name": "dtrupenn/Tetris", "owner": { "login": "dtrupenn", "id": 872147, "node_id": "MDQ6VXNlcjg3MjE0Nw==", "avatar_url": "https://secure.gravatar.com/avatar/e7956084e75f239de85d3a31bc172ace?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png", "gravatar_id": "", "url": "https://api.github.com/users/dtrupenn", "received_events_url": "https://api.github.com/users/dtrupenn/received_events", "type": "User", "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}", "site_admin": true }, "private": false, "html_url": "https://github.com/dtrupenn/Tetris", "description": "A C implementation of Tetris using Pennsim through LC4", "fork": false, "url": "https://api.github.com/repos/dtrupenn/Tetris", "created_at": "2012-01-01T00:31:50Z", "updated_at": "2013-01-05T17:58:47Z", "pushed_at": "2012-01-01T00:37:02Z", "homepage": "https://github.com", "size": 524, "stargazers_count": 1, "watchers_count": 1, "language": "Assembly", "forks_count": 0, "open_issues_count": 0, "master_branch": "master", "default_branch": "master", "score": 1, "archive_url": "https://api.github.com/repos/dtrupenn/Tetris/{archive_format}{/ref}", "assignees_url": "https://api.github.com/repos/dtrupenn/Tetris/assignees{/user}", "blobs_url": "https://api.github.com/repos/dtrupenn/Tetris/git/blobs{/sha}", "branches_url": "https://api.github.com/repos/dtrupenn/Tetris/branches{/branch}", "collaborators_url": "https://api.github.com/repos/dtrupenn/Tetris/collaborators{/collaborator}", "comments_url": "https://api.github.com/repos/dtrupenn/Tetris/comments{/number}", "commits_url": "https://api.github.com/repos/dtrupenn/Tetris/commits{/sha}", "compare_url": "https://api.github.com/repos/dtrupenn/Tetris/compare/{base}...{head}", "contents_url": "https://api.github.com/repos/dtrupenn/Tetris/contents/{+path}", "contributors_url": "https://api.github.com/repos/dtrupenn/Tetris/contributors", "deployments_url": "https://api.github.com/repos/dtrupenn/Tetris/deployments", "downloads_url": "https://api.github.com/repos/dtrupenn/Tetris/downloads", "events_url": "https://api.github.com/repos/dtrupenn/Tetris/events", "forks_url": "https://api.github.com/repos/dtrupenn/Tetris/forks", "git_commits_url": "https://api.github.com/repos/dtrupenn/Tetris/git/commits{/sha}", "git_refs_url": "https://api.github.com/repos/dtrupenn/Tetris/git/refs{/sha}", "git_tags_url": "https://api.github.com/repos/dtrupenn/Tetris/git/tags{/sha}", "git_url": "git:github.com/dtrupenn/Tetris.git", "issue_comment_url": "https://api.github.com/repos/dtrupenn/Tetris/issues/comments{/number}", "issue_events_url": "https://api.github.com/repos/dtrupenn/Tetris/issues/events{/number}", "issues_url": "https://api.github.com/repos/dtrupenn/Tetris/issues{/number}", "keys_url": "https://api.github.com/repos/dtrupenn/Tetris/keys{/key_id}", "labels_url": "https://api.github.com/repos/dtrupenn/Tetris/labels{/name}", "languages_url": "https://api.github.com/repos/dtrupenn/Tetris/languages", "merges_url": "https://api.github.com/repos/dtrupenn/Tetris/merges", "milestones_url": "https://api.github.com/repos/dtrupenn/Tetris/milestones{/number}", "notifications_url": "https://api.github.com/repos/dtrupenn/Tetris/notifications{?since,all,participating}", "pulls_url": "https://api.github.com/repos/dtrupenn/Tetris/pulls{/number}", "releases_url": "https://api.github.com/repos/dtrupenn/Tetris/releases{/id}", "ssh_url": "[email protected]:dtrupenn/Tetris.git", "stargazers_url": "https://api.github.com/repos/dtrupenn/Tetris/stargazers", "statuses_url": "https://api.github.com/repos/dtrupenn/Tetris/statuses/{sha}", "subscribers_url": "https://api.github.com/repos/dtrupenn/Tetris/subscribers", "subscription_url": "https://api.github.com/repos/dtrupenn/Tetris/subscription", "tags_url": "https://api.github.com/repos/dtrupenn/Tetris/tags", "teams_url": "https://api.github.com/repos/dtrupenn/Tetris/teams", "trees_url": "https://api.github.com/repos/dtrupenn/Tetris/git/trees{/sha}", "clone_url": "https://github.com/dtrupenn/Tetris.git", "mirror_url": "git:git.example.com/dtrupenn/Tetris", "hooks_url": "https://api.github.com/repos/dtrupenn/Tetris/hooks", "svn_url": "https://svn.github.com/dtrupenn/Tetris", "forks": 1, "open_issues": 1, "watchers": 1, "has_issues": true, "has_projects": true, "has_pages": true, "has_wiki": true, "has_downloads": true, "archived": true, "disabled": true, "visibility": "private", "license": { "key": "mit", "name": "MIT License", "url": "https://api.github.com/licenses/mit", "spdx_id": "MIT", "node_id": "MDc6TGljZW5zZW1pdA==", "html_url": "https://api.github.com/licenses/mit" } } ] }

搜索主题

通过各种条件查找主题。结果按最佳匹配排序。此方法每 返回多达 100 个结果。有关限定符的详细列表,请参阅“搜索主题”。

搜索主题时,传递 text-match 媒体类型时,可以获取主题的 short_descriptiondescriptionnamedisplay_name 字段的文本匹配元数据。有关如何接收高亮搜索结果的更多详细信息,请参阅 文本匹配元数据

例如,如果你想搜索在 https://github.com/topics 上展示的与 Ruby 相关的主题。你的查询可能如下所示

q=ruby+is:featured

此查询搜索包含关键字 ruby 的主题,并将结果限制为仅查找展示的主题。与查询最匹配的主题会首先出现在搜索结果中。

用于“搜索主题”的细粒度访问令牌

此端点适用于以下细粒度令牌类型

细粒度令牌不需要任何权限。

如果仅请求公共资源,则无需身份验证即可使用此端点。

用于“搜索主题”的参数

标头
名称、类型、说明
accept string

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

查询参数
名称、类型、说明
q string Required

查询包含一个或多个搜索关键字和限定符。限定符允许你将搜索限制到 GitHub 的特定区域。REST API 支持与 GitHub Web 界面相同的限定符。要详细了解查询的格式,请参阅 构建搜索查询

per_page integer

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

默认: 30

page integer

要获取的结果的页码。有关详细信息,请参阅“在 REST API 中使用分页”。

默认: 1

用于“搜索主题”的 HTTP 响应状态代码

状态代码说明
200

正常

304

未修改

用于“搜索主题”的代码示例

请求示例

get/search/topics
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/search/topics?q=Q"

响应

状态: 200
{ "total_count": 6, "incomplete_results": false, "items": [ { "name": "ruby", "display_name": "Ruby", "short_description": "Ruby is a scripting language designed for simplified object-oriented programming.", "description": "Ruby was developed by Yukihiro \"Matz\" Matsumoto in 1995 with the intent of having an easily readable programming language. It is integrated with the Rails framework to create dynamic web-applications. Ruby's syntax is similar to that of Perl and Python.", "created_by": "Yukihiro Matsumoto", "released": "December 21, 1995", "created_at": "2016-11-28T22:03:59Z", "updated_at": "2017-10-30T18:16:32Z", "featured": true, "curated": true, "score": 1 }, { "name": "rails", "display_name": "Rails", "short_description": "Ruby on Rails (Rails) is a web application framework written in Ruby.", "description": "Ruby on Rails (Rails) is a web application framework written in Ruby. It is meant to help simplify the building of complex websites.", "created_by": "David Heinemeier Hansson", "released": "December 13 2005", "created_at": "2016-12-09T17:03:50Z", "updated_at": "2017-10-30T16:20:19Z", "featured": true, "curated": true, "score": 1 }, { "name": "python", "display_name": "Python", "short_description": "Python is a dynamically typed programming language.", "description": "Python is a dynamically typed programming language designed by Guido Van Rossum. Much like the programming language Ruby, Python was designed to be easily read by programmers. Because of its large following and many libraries, Python can be implemented and used to do anything from webpages to scientific research.", "created_by": "Guido van Rossum", "released": "February 20, 1991", "created_at": "2016-12-07T00:07:02Z", "updated_at": "2017-10-27T22:45:43Z", "featured": true, "curated": true, "score": 1 }, { "name": "jekyll", "display_name": "Jekyll", "short_description": "Jekyll is a simple, blog-aware static site generator.", "description": "Jekyll is a blog-aware, site generator written in Ruby. It takes raw text files, runs it through a renderer and produces a publishable static website.", "created_by": "Tom Preston-Werner", "released": "2008", "created_at": "2016-12-16T21:53:08Z", "updated_at": "2017-10-27T19:00:24Z", "featured": true, "curated": true, "score": 1 }, { "name": "sass", "display_name": "Sass", "short_description": "Sass is a stable extension to classic CSS.", "description": "Sass is a stylesheet language with a main implementation in Ruby. It is an extension of CSS that makes improvements to the old stylesheet format, such as being able to declare variables and using a cleaner nesting syntax.", "created_by": "Hampton Catlin, Natalie Weizenbaum, Chris Eppstein", "released": "November 28, 2006", "created_at": "2016-12-16T21:53:45Z", "updated_at": "2018-01-16T16:30:40Z", "featured": true, "curated": true, "score": 1 }, { "name": "homebrew", "display_name": "Homebrew", "short_description": "Homebrew is a package manager for macOS.", "description": "Homebrew is a package manager for Apple's macOS operating system. It simplifies the installation of software and is popular in the Ruby on Rails community.", "created_by": "Max Howell", "released": "2009", "created_at": "2016-12-17T20:30:44Z", "updated_at": "2018-02-06T16:14:56Z", "featured": true, "curated": true, "score": 1 } ] }

搜索用户

通过各种条件查找用户。此方法每页返回多达 100 个结果 每页

在搜索用户时,当你传递 text-match 媒体类型时,你可以获取问题 登录、公共 电子邮件姓名 字段的文本匹配元数据。有关突出显示搜索结果的更多详细信息,请参阅 文本匹配元数据。有关如何接收突出显示的搜索结果的更多详细信息,请参阅 文本匹配元数据

例如,如果你正在寻找热门用户的列表,你可以尝试此查询

q=tom+repos:%3E42+followers:%3E1000

此查询搜索名为 tom 的用户。结果仅限于拥有超过 42 个存储库和超过 1000 个关注者的用户。

此端点不接受身份验证,并且只包含公开可见的用户。作为替代方案,你可以使用 GraphQL API。GraphQL API 需要身份验证,并且会返回你被授权查看的私有用户,包括企业管理用户 (EMU)。有关更多信息,请参阅“GraphQL 查询”。

“搜索用户”的细粒度访问令牌

此端点适用于以下细粒度令牌类型

细粒度令牌不需要任何权限。

如果仅请求公共资源,则无需身份验证即可使用此端点。

“搜索用户”的参数

标头
名称、类型、说明
accept string

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

查询参数
名称、类型、说明
q string Required

查询包含一个或多个搜索关键字和限定符。限定符允许你将搜索限制在 GitHub 的特定区域。REST API 支持与 GitHub Web 界面相同的限定符。若要详细了解查询的格式,请参阅 构建搜索查询。有关限定符的详细列表,请参阅“搜索用户”。

sort string

followersrepositories 的数量,或按该人在 GitHub 中的 joined 时间对查询结果进行排序。默认:最佳匹配

可以是以下之一: followers, repositories, joined

order string

确定返回的第一个搜索结果是匹配数最高(desc)还是匹配数最低(asc)。除非你提供 sort,否则将忽略此参数。

默认: desc

可以是以下之一: desc, asc

per_page integer

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

默认: 30

page integer

要获取的结果的页码。有关详细信息,请参阅“在 REST API 中使用分页”。

默认: 1

“搜索用户”的 HTTP 响应状态代码

状态代码说明
200

正常

304

未修改

422

验证失败,或端点遭到垃圾邮件攻击。

503

服务不可用

“搜索用户”的代码示例

请求示例

get/search/users
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/search/users?q=Q"

响应

状态: 200
{ "total_count": 12, "incomplete_results": false, "items": [ { "login": "mojombo", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://secure.gravatar.com/avatar/25c7c18223fb42a4c6ae1c8db6f50f9b?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png", "gravatar_id": "", "url": "https://api.github.com/users/mojombo", "html_url": "https://github.com/mojombo", "followers_url": "https://api.github.com/users/mojombo/followers", "subscriptions_url": "https://api.github.com/users/mojombo/subscriptions", "organizations_url": "https://api.github.com/users/mojombo/orgs", "repos_url": "https://api.github.com/users/mojombo/repos", "received_events_url": "https://api.github.com/users/mojombo/received_events", "type": "User", "score": 1, "following_url": "https://api.github.com/users/mojombo/following{/other_user}", "gists_url": "https://api.github.com/users/mojombo/gists{/gist_id}", "starred_url": "https://api.github.com/users/mojombo/starred{/owner}{/repo}", "events_url": "https://api.github.com/users/mojombo/events{/privacy}", "site_admin": true } ] }