Почему Github API возвращает только первые 100 просматриваемых репозиториев?

Я смотрю 392 репозитория на Github. Однако Github API возвращает только 100. Кто-нибудь знает, почему?

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


person trivektor    schedule 16.10.2011    source источник


Ответы (2)


Вам нужно разбивать страницы вручную, используя параметр 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
person plu    schedule 22.10.2011

Очень часто API ограничивают размер объекта ответа для защиты от выбросов. Учитывая, что он возвращает круглое число, это предполагает, что это сделано по замыслу. Я не вижу, чтобы они обсуждали подкачку в своих документах, так что это может быть просто ограничение. В любом случае, вы должны просто пинговать github.

person John Hinnegan    schedule 16.10.2011