【问题标题】:Github API: How to sort public repositories by count of stars?Github API:如何按星数对公共存储库进行排序?
【发布时间】:2014-07-17 14:44:36
【问题描述】:

我正在 github 上寻找 api,它可以为我提供存储库的星数

我知道/repositories 为我提供公共存储库,但我不知道如何获取存储库的星数。

有人可以帮忙吗?

【问题讨论】:

    标签: github-api


    【解决方案1】:

    /repositories 获取所有公共存储库。作为回应,您将获得所有者的名称以及存储库名称,然后在每个存储库上使用 Get。在每个存储库的响应中,stargazers_count 字段将为您提供每个存储库拥有的星数。

    一些示例python代码:

    import requests
    public_repos = requests.get('https://api.github.com/repositories').json()
    
    for repo in public_repos:
        repo_name = repo['name']
        owner = repo['owner']['login']  
        repo_info = requests.get('https://api.github.com/repos/'+owner+'/'+repo_name)
        stars = repo_info.json()['stargazers_count']
        print(repo_name, stars)
    

    输出是:

    grit 1874
    merb-core 401
    rubinius 2176
    god 1592
    jsawesome 12
    

    看看/repositoriesGet

    【讨论】:

    • 它很容易达到速率限制
    • @Longerian 你可以轻松地传递访问令牌。
    猜你喜欢
    • 1970-01-01
    • 2017-07-29
    • 1970-01-01
    • 2021-04-07
    • 2013-12-11
    • 2018-10-07
    • 1970-01-01
    • 2019-05-03
    • 2023-01-10
    相关资源
    最近更新 更多