为什么Github API只返回前100个监视存储库? [英] Why does Github API only returns the first 100 watched repositories?

查看:112
本文介绍了为什么Github API只返回前100个监视存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Github上观看392个存储库。然而,Github API只返回100.有人知道为什么吗?



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



示例:

  curl -D- https://github.com/api/v2/json/repos/watched/trivektor 
HTTP / 1.1 200 OK
服务器:nginx / 1.0.4
日期:2011年10月22日星期六08:24:45 GMT
Content-Type:application / json; charset = utf-8
连接:keep-alive
状态: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

现在第二页:

  curl -D- https://github.com/api/v2/json/repos/watched/trivektor?page=2 
HTTP / 1.1 200 OK
Server:nginx / 1.0.4
日期:2011年10月22日(星期六)08:28:08 GMT
Content-Type:application / json; charset = utf-8
连接:keep-alive
状态: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-控制:private,max-age = 0,必须重新验证

最后一个:

  curl -D- https://github.com/api/v2/json/repos/watched/trivektor?page=5 
HTTP / 1.1 200 OK
服务器:nginx / 1.0.4
日期:2011年10月22日(星期六)08:28:30 GMT
Content-Type:application / json; charset = utf-8
连接:keep-alive
状态:200 OK
X-RateLimit-Limit:60
ETag:11ce44ebc229eab0dc31731b39e10dcf
X-Frame-选项:deny
X-RateLimit-Remaining:57
X-Runtime:93ms
Content-Length:7056
Cache-Control:private,max-age = 0,must-重新验证


I'm watching 392 repositories on Github. However, the Github API only returns 100. Does anyone have any idea why?

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

解决方案

You need to paginate manually using the page parameter. The HTTP Response headers will tell you the next and the last page, if available. Check the headers:

  • X-Next
  • X-Last

Examples:

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

Now the 2nd page:

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

And the last one:

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

这篇关于为什么Github API只返回前100个监视存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆