我需要使用github API v3(https://developer.github.com/v3/)和标准获取活动用户的登录(最多30个)以及在存储库的特定分支中给定时间段内的提交数量python库。我研究了一般api文档,特别是https://developer.github.com/v3/repos/和https://developer.github.com/v3/search/文章,但我找不到如何做到这一点。可以通过查找提交
GET /search/commits
(通过repo参数指定存储库:https://api.github.com/search/commits?q=repo:octocat/Spoon-Knife
),但既没有指定时间段也没有指定存储库分支。
因此,我能够获得登录和贡献,但仅限于整个时间:
https://api.github.com/repos/octocat/Spoon-Knife/contributors
此外,为了使搜索提交有效,在Accept
标题中提供自定义媒体类型是必要的:application/vnd.github.cloak-preview
我已经从urlib
库的工作原理的文档中重新编写了一个示例,但它返回HTTP error 422
:
import urllib.request
API_URL = "https://api.github.com/"
q = urllib.request.Request('API_URL' + "search/commits?q=repo:octocat/Spoon-Knife")
https://api.github.com/search/commits?q=repo:fastlane/fastlane
q.add_header('application/vnd.github.cloak-preview', 'Accept')
print(q)
a = urllib.request.urlopen(q)
a = a.read()
print(a)