我尝试在GitHub中获取组织中的所有用户。我可以获得用户,但是我有分页问题 - 我不知道我必须有多少页才能解决。如何在GitHub中获取组织中的所有用户?
curl -i -s -u "user:pass" 'https://api.github.com/orgs/:org/members?page=1&per_page=100'
当然我可以遍历所有的页面,直到我的要求将不会返回“0”,但我觉得这不是个好主意)
也许GitHub上有标准方法获得组织中的所有用户?
我尝试在GitHub中获取组织中的所有用户。我可以获得用户,但是我有分页问题 - 我不知道我必须有多少页才能解决。如何在GitHub中获取组织中的所有用户?
curl -i -s -u "user:pass" 'https://api.github.com/orgs/:org/members?page=1&per_page=100'
当然我可以遍历所有的页面,直到我的要求将不会返回“0”,但我觉得这不是个好主意)
也许GitHub上有标准方法获得组织中的所有用户?
据Traversing with Pagination,应该有一个Link response header,如:
Link: <https://api.github.com/orgs/:org/members?page=2>; rel="next", <https://api.github.com/orgs/:org/members?page=3>; rel="last"
这些标题应该给你需要这样您就可以继续获得页面的所有信息。
由于性能方面的原因,我认为任何API都不能绕过分页。
谢谢Jean,就是这样! 我知道关于“链接回应标题”,但我测试这是我的测试组织,其中只包含10人,当然我没有看到这一行(链接:...)... 当我尝试在另一个组织,我明白了! 谢谢! – 2014-10-31 12:06:05
您可以使用PyGithub - Python库实现GitHub的API V3 http://jacquev6.github.io/PyGithub
而且我的脚本临危所有的组织成员,并将它们添加到一个组: https://github.com/Nmishin/updater
这里是我的github-users
脚本实例:
#!/usr/bin/env ruby
require 'octokit'
Octokit.configure do |c|
c.login = '....'
c.password = '...'
end
get = Octokit.org(ARGV.first).rels[:public_members].get
members = get.data
urls = members.map(&:url)
while members.size > 0
next_url = get.rels[:next]
next members = [] unless next_url
get = next_url.get
members = get.data
urls << members.map(&:url)
end
puts urls
例如github-members stackexchange
给出:
https://api.github.com/users/JasonPunyon
https://api.github.com/users/JonHMChan
https://api.github.com/users/NickCraver
https://api.github.com/users/NickLarsen
https://api.github.com/users/PeterGrace
https://api.github.com/users/bretcope
https://api.github.com/users/captncraig
https://api.github.com/users/df07
https://api.github.com/users/dixon
https://api.github.com/users/gdalgas
https://api.github.com/users/haneytron
https://api.github.com/users/jc4p
https://api.github.com/users/kevin-montrose
https://api.github.com/users/kirtithorat
https://api.github.com/users/kylebrandt
https://api.github.com/users/momow
https://api.github.com/users/ocoster-se
https://api.github.com/users/robertaarcoverde
https://api.github.com/users/rossipedia
https://api.github.com/users/shanemadden
https://api.github.com/users/sklivvz
https://developer.github.com/guides/traversing-with-pagination/#consuming-the-information。 – 2014-10-31 11:28:40