aun*_*uny 9 api github github-api
GitHub API提供了一种获取组织成员的方法.我是我的组织的管理员/所有者,我想获得所有用户的电子邮件地址.我尝试使用membersAPI但它没有返回电子邮件地址.
在我的管理员中使用curl auth-token:
GET /orgs/my-org/members
Run Code Online (Sandbox Code Playgroud)
我得到的响应看起来像这样(对于其中一个用户)
"login": "auny",
"id": some-number,
"avatar_url": "https://secure.gravatar.com/avatar/6579d09c459f1adad8a60463f47eadd3?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
"gravatar_id": "6579d09c459f1adad8a60463f47eadd3",
"url": "https://api.github.com/users/auny",
"html_url": "https://github.com/auny",
"followers_url": "https://api.github.com/users/auny/followers",
"following_url": "https://api.github.com/users/auny/following{/other_user}",
"gists_url": "https://api.github.com/users/auny/gists{/gist_id}",
"starred_url": "https://api.github.com/users/auny/starred{/owner}
{/repo}",
"subscriptions_url": "https://api.github.com/users/auny/subscriptions",
"organizations_url": "https://api.github.com/users/auny/orgs",
"repos_url": "https://api.github.com/users/auny/repos",
"events_url": "https://api.github.com/users/auny/events{/privacy}",
"received_events_url":
"https://api.github.com/users/auny/received_events",
"type": "User"
Run Code Online (Sandbox Code Playgroud)
奇怪的是,这包含有关用户的大量信息,但不包含重要信息之一,即用户的电子邮件地址.作为admin我应该能够获得所有用户的电子邮件地址.
其他用户API仅返回我自己的电子邮件地址,即auth-token请求中使用的帐户的电子邮件地址.API用法:
GET /user/emails
Run Code Online (Sandbox Code Playgroud)
怎么能实现这一目标?周围有路吗?
使用GraphQL API v4,您不必为每个用户调用一个请求。以下将获得组织成员及其email(如果在公开资料中提供):
{
organization(login: "my-org") {
membersWithRole(first: 100) {
totalCount
edges {
node {
login
name
email
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
[编辑 08/2020]使用membersWithRole代替不推荐使用的members字段
您可以改用git仓库!里面有很多有趣的信息。
尝试运行:
git shortlog -s -n -e
Run Code Online (Sandbox Code Playgroud)
您将看到带有电子邮件地址的提交者列表。
获取组织成员列表后,使用此 API 端点获取每个成员的信息:
/users/:user
Run Code Online (Sandbox Code Playgroud)
这将返回您在请求 URL 中指定的用户的电子邮件地址。
| 归档时间: |
|
| 查看次数: |
6331 次 |
| 最近记录: |