Github API v3不会显示所有用户存储库 [英] Github API v3 doesn't show all user repositories

查看:147
本文介绍了Github API v3不会显示所有用户存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我键入以下命令:

$ curl https://api.github.com/users/KiCad/repos | grep full_name

我希望它将返回所有KiCad存储库,但返回:

I expect that it will return all KiCad repositories, but it returns:

"full_name": "KiCad/Air_Coils_SML_NEOSID.pretty",
"full_name": "KiCad/Buzzers_Beepers.pretty",
"full_name": "KiCad/Capacitors_Elko_ThroughHole.pretty",
"full_name": "KiCad/Capacitors_SMD.pretty",
"full_name": "KiCad/Capacitors_Tantalum_SMD.pretty",
"full_name": "KiCad/Capacitors_ThroughHole.pretty",
"full_name": "KiCad/Choke_Axial_ThroughHole.pretty",
"full_name": "KiCad/Choke_Common-Mode_Wurth.pretty",
"full_name": "KiCad/Choke_Radial_ThroughHole.pretty",
"full_name": "KiCad/Choke_SMD.pretty",
"full_name": "KiCad/Choke_Toroid_ThroughHole.pretty",
"full_name": "KiCad/Connect.pretty",
"full_name": "KiCad/Connectors_Molex.pretty",
"full_name": "KiCad/Converters_DCDC_ACDC.pretty",
"full_name": "KiCad/Crystals.pretty",
"full_name": "KiCad/Crystals_Oscillators_SMD.pretty",
"full_name": "KiCad/Diodes_SMD.pretty",
"full_name": "KiCad/Diodes_ThroughHole.pretty",
"full_name": "KiCad/Discret.pretty",
"full_name": "KiCad/Display.pretty",
"full_name": "KiCad/Displays_7-Segment.pretty",
"full_name": "KiCad/Divers.pretty",
"full_name": "KiCad/EuroBoard_Outline.pretty",
"full_name": "KiCad/Fiducials.pretty",
"full_name": "KiCad/Filters_HF_Coils_NEOSID.pretty",
"full_name": "KiCad/Fuse_Holders_and_Fuses.pretty",
"full_name": "KiCad/Hall-Effect_Transducers_LEM.pretty",
"full_name": "KiCad/Heatsinks.pretty",
"full_name": "KiCad/Housings_DFN_QFN.pretty",
"full_name": "KiCad/Housings_QFP.pretty",

如果您查看 https://github.com/KiCad ,您会看到,还有更多的存储库。

If you look at https://github.com/KiCad, you will see, that there are more repositories.

有人遇到过这个问题吗?

Has anyone encountered this problem? How do you solve it?

推荐答案

GitHub API使用分页,默认为每页30个项目。您将不得不使用

The GitHub API uses pagination and defaults to 30 items per page. You will have to use

curl -i https://api.github.com/users/KiCad/repos?per_page=100

100是您在单个页面上可获得的最多项目数。指定 -i 后,您将看到打印出的标题,而您要查找的标题是 Links 标题。它将具有帮助您浏览页面的链接。这些链接之一应该看起来像

100 is the most number of items you can get on a single page. With -i specified you'll see headers printed out and the header you're looking for is the Links header. That will have links to help you navigate the pages. One of those links should look like

https://api.github.com/users/KiCad/repos?per_page=100&page=2

因此,如果您这样做

curl -i https://api.github.com/users/KiCad/repos?per_page=100&page=2

您将获得回购101-200。您可以继续执行此操作,直到 Links 标题中没有任何 next 链接,或者直到您知道收到的信息少于100个结果。

You'll get repos 101-200. You can continue this until there is no next link in the Links header or until you realize you've received fewer than 100 results.

这篇关于Github API v3不会显示所有用户存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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