Python 3.x 为什么github api给了我一个较低的回购数量?
我使用下面的代码来获取回购的星,但它只返回40000星的引导回购,这比实际的70717星要低。但是,它返回JQuery repo的正确星号(31445)。为什么检索引导的星星是不正确的Python 3.x 为什么github api给了我一个较低的回购数量?,python-3.x,github,github-api,Python 3.x,Github,Github Api,我使用下面的代码来获取回购的星,但它只返回40000星的引导回购,这比实际的70717星要低。但是,它返回JQuery repo的正确星号(31445)。为什么检索引导的星星是不正确的 #!/usr/bin/python from github import Github # XXX: Specify your own access token here ACCESS_TOKEN = '' client = Github(ACCESS_TOKEN, per_page=100) # Specify
#!/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))
响应正文将指示给定资源列表的分页是否受到限制:
❯ 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"
}
Github API中的分页有一个限制(即400)
过去,当从Github项目中提取信息时,没有人达到此限制,因为正在提取的记录数(例如,问题中的星星或帖子中的问题事件)没有达到40000(即40乘以100)的限制
如今,一些项目(如twb/bootstrap或rails/rails)增长太多,当前的分页无法获取全部信息,到目前为止,我还没有看到任何机制可以解决这个问题
这是Github应该关心并重新考虑其API设计的问题。这似乎是一个API限制。正如正文所示,我们为一些负载密集型资源设置了分页上限。如果您只想要足够数量的stargazers,获取stargazers列表会非常昂贵。我想你最好通过搜索结果来获得这些信息:@sigmavirus24是的,thx~@markusuenterwaditzer thx~那么你应该做些什么来吸引所有的明星呢?我的意思是当超过400页时,正如我在这里提到的: