通过分页获取所有公共github存储库 [英] Get all public github repositories with pagination

查看:76
本文介绍了通过分页获取所有公共github存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取所有带有分页的公共Github存储库(api.github.com/repositories)(例如,通过10个存储库获取它).我尝试了 https://api.github.com/repositories?page=2& per_page = 10 ,但仅适用于搜索,但不适用于所有公共存储库.如何通过分页获取所有公共回购协议?

I want to get all public Github repositories (api.github.com/repositories) with pagination (for example, get it by 10 repos). I tried https://api.github.com/repositories?page=2&per_page=10, but it's works only on search, but doesn't work on all public repos. How To get all public repos with pagination?

推荐答案

在Github API文档中对此进行了解释,请参见

This is explained in the Github API documentation, see https://developer.github.com/v3/repos/#list-all-public-repositories.

使用since URL参数而不是page进行分页,since的值是您已经看到的最后一个存储库的数字ID. 如果省略since参数,则响应将返回存储库列表,第一个存储库的ID为1.要获取下一页,请在下一个请求中添加?since=369(369是我在请求第一页时获得的最后一个ID).

The pagination is done by using the since URL parameter instead of page, the value of since is the numerical id of the last repository that you already have seen. If you omit the since parameter the response will return a list of repositories, the first repo has id 1. To get the next page you add ?since=369 to the next request (369 is the last id that I get when requesting the first page).

为方便起见,响应还包括Link标头,其中包含指向下一页的现成URL.

For convenience the responses also includes the Link header which contains a ready-made URL to the next page.

这篇关于通过分页获取所有公共github存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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