为什么 GitHub API 显示某个仓库的星数比实际少?

3
我使用以下代码获取存储库的星标,但它只返回Bootstrap存储库的40000个星标,低于实际的70717个星标。然而,它返回正确的JQuery存储库的星标(31445)。为什么检索Bootstrap的星标不正确?
#!/usr/bin/python
from github import Github
# XXX: Specify your own access token here
ACCESS_TOKEN = ''
client = Github(ACCESS_TOKEN, per_page=100)
# Specify a username and repository of interest for that user.
REPO_LIST=[('twbs','bootstrap'),('jquery','jquery')]
for USER,REPO in REPO_LIST:
    user = client.get_user(USER)
    repo = user.get_repo(REPO)
    # Get a list of people who have bookmarked the repo.
    # Since you'll get a lazy iterator back, you have to traverse
    # it if you want to get the total number of stargazers.
    stargazers = [ s for s in repo.get_stargazers() ]
    print("Number of stargazers", len(stargazers))

这似乎是一个API限制。 - Ian Stapleton Cordasco
1
我们对一些负载较重的资源进行了分页限制,正如正文所示。 - pengwynn
1
如果你只想获取点赞者的数量,那么获取点赞者列表是非常昂贵的。我认为你最好通过搜索结果来获取这些信息:https://developer.github.com/v3/search/#search-repositories - Markus Unterwaditzer
@sigmavirus24 是的,谢谢~ - leafonsword
@MarkusUnterwaditzer 谢谢~ - leafonsword
2个回答

6
响应主体将指示特定资源列表的分页是否受限:
❯ curl https://api.github.com/repos/twbs/bootstrap/stargazers\?per_page\=100\&page\=401
{
  "message": "In order to keep the API fast for everyone, pagination is limited for this resource. Check the rel=last link relation in the Link response header to see how far back you can traverse.",
  "documentation_url": "https://developer.github.com/v3/#pagination"
}

那么,当有超过400页时,您应该如何获取所有星星呢?就像我在这里提到的那样:http://stackoverflow.com/q/40795229/2961878 - Alisa
@Alisa,你能确定如何获取所有数据吗? - Deekshant

4

Github API有分页限制(即400条)。

过去,从Github项目中拉取信息时,没有人达到这个限制,因为被拉取的记录数量(例如您提出的stars,或者文章中的问题事件)没有达到40000(即40*100)的限制。

现在,一些项目(如twbs/bootstrap或rails/rails)已经增长得太大,当前的分页无法拉取完整的信息,目前我没有看到任何解决此问题的机制。

这是Github应该关注和重新考虑其API设计的事情。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接