如何找到我的 GitHub 组织 ID?
理想情况下,通过脚本或命令我可以解析其输出。
类型:
curl -H "Authorization: token OAUTH-TOKEN" https://api.github.com/organizations
(将
OAUTH-TOKEN
替换为您自己的 GitHub 访问令牌:请参阅“使用 OAuth 令牌的 Git 自动化”以获取或创建 PAT:个人访问令牌)
您将看到您可以在下面访问多个组织。
对于每一个:
curl -H "Accept: application/json" -H "Authorization: token OAUTH-TOKEN" https://api.github.com/organizations/<anorg> | jq ".id"
jq
(轻量级命令行 JSON 处理器,适用于所有操作系统,包括 Windows),您将直接获得 id。
curl -H "Authorization: token personal-access-token" https://api.github.com/orgs/name-of-your-org
此命令输出如下所示:
{
"login": "your-org",
"id": 15156947,
"url": "https://api.github.com/orgs/your-org",
"repos_url": "https://api.github.com/orgs/your-org/repos",
"events_url": "https://api.github.com/orgs/your-org/events",
"hooks_url": "https://api.github.com/orgs/your-org/hooks",
"issues_url": "https://api.github.com/orgs/your-org/issues",
"members_url": "https://api.github.com/orgs/your-org/members{/member}",
"public_members_url": "https://api.github.com/orgs/your-org/public_members{/member}",
"avatar_url": "https://avatars.githubusercontent.com/u/15056937?v=3",
"description": "",
"name": "",
"company": null,
"blog": "",
"location": "",
"email": "",
"public_repos": 1,
"public_gists": 0,
"followers": 0,
"following": 0,
"html_url": "https://github.com/your-org",
"created_at": "2013-11-09T21:58:06Z",
"updated_at": "2014-09-18T16:54:44Z",
"type": "Organization",
"total_private_repos": 0,
"owned_private_repos": 0,
"private_gists": 0,
"disk_usage": 0,
"collaborators": 0,
"billing_email": "[email protected]",
"plan": {
"name": "free",
"space": 976562499,
"private_repos": 0,
"filled_seats": 2,
"seats": 0
}
}
因此第二行包含所需的组织 ID:
"id": 15156947
希望对其他人有帮助。