我尝试在GitHub中获取组织中的所有用户。我可以得到用户,但我有分页问题 - 我不知道有多少页我必须绕过。
curl -i -s -u "user:pass" 'https://api.github.com/orgs/:org/members?page=1&per_page=100'
当然我可以迭代所有页面,直到我的请求不会返回“0”,但我认为这不是一个好主意)
也许GitHub有获取组织中所有用户的标准方法?
答案 0 :(得分:1)
根据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可以绕过分页。
答案 1 :(得分:0)
以下是我的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
e.g。 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
答案 2 :(得分:-1)
你可以使用PyGithub - Python库实现GitHub API v3 http://jacquev6.github.io/PyGithub
我的脚本收到所有组织成员并将它们添加到一个组中: https://github.com/Nmishin/updater