首页 > 解决方案 > 使用日期查询使用 GitHub API 搜索存储库

问题描述

如果我向 GitHub API 发出以下 GET 请求,我会得到大约 58 个条目:

https://api.github.com/search/repositories?&per_page=250&sort=updated&order=asc&q=%22github-octocat%22

但是,带有任何日期参数的以下内容返回 0 个条目:

创建日期: ( created:>=2010-09-01)

https://api.github.com/search/repositories?&per_page=250&sort=updated&order=asc&q=%22github-octocat+created:>=2010-09-01%22

日期范围: ( created:2012-08-13..2020-08-14)

https://api.github.com/search/repositories?&per_page=250&sort=updated&order=asc&q=%22github-octocat+created:2012-08-13..2020-08-14%22

在 GitHub 文档中,在Constructing a search query部分下,语法概述如下:

SEARCH_KEYWORD_1 SEARCH_KEYWORD_N QUALIFIER_1 QUALIFIER_N

Thei GitHub docs at Search by when a repository was created or last updated概述了上述两种日期格式,查询范围内的值概述了它们的有效组合。我怀疑这些示例并非用于此用途,因为这些示例使用用于浏览器的 URL,例如https://github.com/search?q=case+pushed%3A%3E%3D2013-03-06+fork%3Aonly&type=Repositories, 而不是api.github.com,这也令人困惑。

我正在尝试应用以下资源中显示的模式以获得一系列日期过滤器:

任何指针都非常感谢。

标签: apihttpgithubhttprequest

解决方案


尽管 GitHub 文档概述了这样的语法:

SEARCH_KEYWORD_1 SEARCH_KEYWORD_N QUALIFIER_1 QUALIFIER_N

日期或类似的参数是无效的,除非放在q参数之外。而不是在双引号内包含date限定符(如下%22所示):

q=%22mysearch+pushed%3A2017-09-01..2020-10-01+sort:updated%22

将它们拉出,并将它们添加到q参数的右引号之后:

q=%22mystring%22+pushed%3A2017-09-01..2020-10-01+sort:updated

推荐阅读