【问题标题】:Why does Github API only returns the first 100 watched repositories?为什么 Github API 只返回前 100 个观看的仓库?
【发布时间】:2011-10-16 17:42:18
【问题描述】:

我正在查看 Github 上的 392 个存储库。但是,Github API 只返回 100。有人知道为什么吗?

https://github.com/api/v2/json/repos/watched/trivektor

【问题讨论】:

    标签: github github-api


    【解决方案1】:

    您需要使用page 参数手动分页。 HTTP 响应标头将告诉您下一页和最后一页(如果可用)。检查标题:

    • X-Next
    • X-Last

    例子:

    curl -D- https://github.com/api/v2/json/repos/watched/trivektor
    HTTP/1.1 200 OK
    Server: nginx/1.0.4
    Date: Sat, 22 Oct 2011 08:24:45 GMT
    Content-Type: application/json; charset=utf-8
    Connection: keep-alive
    Status: 200 OK
    X-RateLimit-Limit: 60
    ETag: "c597e396e9f17b91c5c5a7e462ba954f"
    X-Next: https://github.com/api/v2/json/repos/watched/trivektor?page=2
    X-Last: https://github.com/api/v2/json/repos/watched/trivektor?page=5
    

    现在是第 2 页:

    curl -D- https://github.com/api/v2/json/repos/watched/trivektor?page=2
    HTTP/1.1 200 OK
    Server: nginx/1.0.4
    Date: Sat, 22 Oct 2011 08:28:08 GMT
    Content-Type: application/json; charset=utf-8
    Connection: keep-alive
    Status: 200 OK
    X-RateLimit-Limit: 60
    ETag: "c57d0e97e2062672cb3771467cf2abc7"
    X-Next: https://github.com/api/v2/json/repos/watched/trivektor?page=3
    X-Last: https://github.com/api/v2/json/repos/watched/trivektor?page=5
    X-Frame-Options: deny
    X-RateLimit-Remaining: 58
    X-Runtime: 353ms
    Content-Length: 44966
    Cache-Control: private, max-age=0, must-revalidate
    

    最后一个:

    curl -D- https://github.com/api/v2/json/repos/watched/trivektor?page=5
    HTTP/1.1 200 OK
    Server: nginx/1.0.4
    Date: Sat, 22 Oct 2011 08:28:30 GMT
    Content-Type: application/json; charset=utf-8
    Connection: keep-alive
    Status: 200 OK
    X-RateLimit-Limit: 60
    ETag: "11ce44ebc229eab0dc31731b39e10dcf"
    X-Frame-Options: deny
    X-RateLimit-Remaining: 57
    X-Runtime: 93ms
    Content-Length: 7056
    Cache-Control: private, max-age=0, must-revalidate
    

    【讨论】:

      【解决方案2】:

      API 限制响应对象的大小以防止异常值非常常见。鉴于它返回一个整数,这表明这是设计使然。我没有看到他们在他们的文档中讨论分页,所以这可能只是一个硬上限。无论哪种方式,您都应该 ping github。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-08-17
        • 1970-01-01
        • 1970-01-01
        • 2016-07-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-30
        相关资源
        最近更新 更多