我正在使用以下代码来获得回购的星星,但它只返回40000颗Bootstrap回购,这比实际的70717颗星要低。然而,它返回JQuery repo的正确星(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))
答案 0 :(得分:4)
响应正文将指出给定资源列表的分页是否有限:
❯ 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"
}
答案 1 :(得分:1)
Github API中的分页存在限制(即400)。
过去,当从Github项目中提取信息时,没有人达到此限制,因为正在提取的记录数量(例如,您的问题中的星标,或this帖子中发布的事件)未达到40,000(即40倍100)限制。
如今,一些项目(如twbs / bootstrap或rails / rails)增长太多,目前的分页无法提取全部信息,截至目前,我还没有看到任何解决此问题的机制。
这是Github应该关心并重新考虑其API设计的东西。