我正在使用以下代码来获取存储库的星星,但它仅返回40000颗Bootstrap存储库的星星,低于实际的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))

最佳答案

响应正文将指示对于给定的资源列表,分页是否受到限制:

❯ 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"
}

关于python-3.x - 为什么github api给我 repo 的星数更少?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25265465/

10-12 18:14