如何使用V3 API列出所有Github用户?

时间:2013-03-29 22:44:46

标签: ruby api curl github github-api

我只能得到前100位用户:

lsoave@ubuntu:~$ curl -i https://api.github.com/users|grep -c login
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  104k  100  104k    0     0  92808      0  0:00:01  0:00:01 --:--:--  100k
100
lsoave@ubuntu:~$ 

但我需要完整列表和/ users?page =(其中n从0变为)获得相同的100个用户列表:

lsoave@ubuntu:~$ curl -i https://api.github.com/users?page=0 | grep login | tail -10
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  104k  100  104k    0     0  90797      0  0:00:01  0:00:01 --:--:--  101k
    "login": "danielharan",
    "login": "kvnsmth",
    "login": "collectiveidea",
    "login": "canadaduane",
    "login": "nate",
    "login": "dstrelau",
    "login": "sunny",
    "login": "dkubb",
    "login": "jnicklas",
    "login": "richcollins",

lsoave@ubuntu:~$ curl -i https://api.github.com/users?page=1 | grep login | tail -10
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  104k  100  104k    0     0    99k      0  0:00:01  0:00:01 --:--:--  110k
    "login": "danielharan",
    "login": "kvnsmth",
    "login": "collectiveidea",
    "login": "canadaduane",
    "login": "nate",
    "login": "dstrelau",
    "login": "sunny",
    "login": "dkubb",
    "login": "jnicklas",
    "login": "richcollins",

lsoave@ubuntu:~$ curl -i https://api.github.com/users?page=2 | grep login | tail -10
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  104k  100  104k    0     0  95960      0  0:00:01  0:00:01 --:--:--  104k
    "login": "danielharan",
    "login": "kvnsmth",
    "login": "collectiveidea",
    "login": "canadaduane",
    "login": "nate",
    "login": "dstrelau",
    "login": "sunny",
    "login": "dkubb",
    "login": "jnicklas",
    "login": "richcollins",

lsoave@ubuntu:~$ curl -i https://api.github.com/users?page=3 | grep login | tail -10
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  104k  100  104k    0     0    99k      0  0:00:01  0:00:01 --:--:--  110k
    "login": "danielharan",
    "login": "kvnsmth",
    "login": "collectiveidea",
    "login": "canadaduane",
    "login": "nate",
    "login": "dstrelau",
    "login": "sunny",
    "login": "dkubb",
    "login": "jnicklas",
    "login": "richcollins",

1 个答案:

答案 0 :(得分:2)

您需要使用since参数而不是页面

理想情况下,您会获得列表中最后一个用户的id(在这种情况下,它是 135 )并且您使用该ID进行下一次调用,新响应将包含超过该用户标识的用户

https://api.github.com/users?since=135