Skip to content

[Github] REST API 取得 user/repo 公開資訊

Published: at 01:40 PM (3 min read)

有時候工作上會用到一些非官方文件提到的 github REST API 查詢資料,整理一些不在官方文件中的不需要授權的 REST APIs

table of contents

Open table of contents

非官方文件紀錄 REST APIs

需要注意的是這些非官方文件記錄的 APIs 基本上都只能抓到公開資料,換句話說,你未登入看不到的資料基本上都是抓不到的。 例如: private repo

username 取得 user 資料

curl -s https://api.github.com/users/:username
Response
{
  "login": "camel2243",
  "id": 6596434,
  "node_id": "MDQ6VXNlcjY1OTY0MzQ=",
  "avatar_url": "https://avatars.githubusercontent.com/u/6596434?v=4",
  "gravatar_id": "",
  "url": "https://api.github.com/users/camel2243",
  "html_url": "https://github.com/camel2243",
  "followers_url": "https://api.github.com/users/camel2243/followers",
  "following_url": "https://api.github.com/users/camel2243/following{/other_user}",
  "gists_url": "https://api.github.com/users/camel2243/gists{/gist_id}",
  "starred_url": "https://api.github.com/users/camel2243/starred{/owner}{/repo}",
  "subscriptions_url": "https://api.github.com/users/camel2243/subscriptions",
  "organizations_url": "https://api.github.com/users/camel2243/orgs",
  "repos_url": "https://api.github.com/users/camel2243/repos",
  "events_url": "https://api.github.com/users/camel2243/events{/privacy}",
  "received_events_url": "https://api.github.com/users/camel2243/received_events",
  "type": "User",
  "user_view_type": "public",
  "site_admin": false,
  "name": "camel2243",
  "company": null,
  "blog": "http://blog.camel2243.com/",
  "location": null,
  "email": null,
  "hireable": null,
  "bio": "No pain, no gain 🌾",
  "twitter_username": null,
  "public_repos": 22,
  "public_gists": 9,
  "followers": 2,
  "following": 0,
  "created_at": "2014-02-05T16:00:38Z",
  "updated_at": "2025-02-28T13:48:25Z"
}

user_id 取得 user 資料

curl -s https://api.github.com/user/:user_id
Response
{
  "login": "camel2243",
  "id": 6596434,
  "node_id": "MDQ6VXNlcjY1OTY0MzQ=",
  "avatar_url": "https://avatars.githubusercontent.com/u/6596434?v=4",
  "gravatar_id": "",
  "url": "https://api.github.com/users/camel2243",
  "html_url": "https://github.com/camel2243",
  "followers_url": "https://api.github.com/users/camel2243/followers",
  "following_url": "https://api.github.com/users/camel2243/following{/other_user}",
  "gists_url": "https://api.github.com/users/camel2243/gists{/gist_id}",
  "starred_url": "https://api.github.com/users/camel2243/starred{/owner}{/repo}",
  "subscriptions_url": "https://api.github.com/users/camel2243/subscriptions",
  "organizations_url": "https://api.github.com/users/camel2243/orgs",
  "repos_url": "https://api.github.com/users/camel2243/repos",
  "events_url": "https://api.github.com/users/camel2243/events{/privacy}",
  "received_events_url": "https://api.github.com/users/camel2243/received_events",
  "type": "User",
  "user_view_type": "public",
  "site_admin": false,
  "name": "camel2243",
  "company": null,
  "blog": "http://blog.camel2243.com/",
  "location": null,
  "email": null,
  "hireable": null,
  "bio": "No pain, no gain 🌾",
  "twitter_username": null,
  "public_repos": 22,
  "public_gists": 9,
  "followers": 2,
  "following": 0,
  "created_at": "2014-02-05T16:00:38Z",
  "updated_at": "2025-02-28T13:48:25Z"
}

username / repo_name 取得 repo 資料 (node_id 即為 repo_id)

curl -s https://api.github.com/repos/:username/:repo_name
Response
{
  "id": 938938531,
  "node_id": "R_kgDON_cQow",
  "name": "camel-blog-comments",
  "full_name": "camel2243/camel-blog-comments",
  "private": false,
  "owner": {
    "login": "camel2243",
    "id": 6596434,
    "node_id": "MDQ6VXNlcjY1OTY0MzQ=",
    "avatar_url": "https://avatars.githubusercontent.com/u/6596434?v=4",
    "gravatar_id": "",
    "url": "https://api.github.com/users/camel2243",
    "html_url": "https://github.com/camel2243",
    "followers_url": "https://api.github.com/users/camel2243/followers",
    "following_url": "https://api.github.com/users/camel2243/following{/other_user}",
    "gists_url": "https://api.github.com/users/camel2243/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/camel2243/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/camel2243/subscriptions",
    "organizations_url": "https://api.github.com/users/camel2243/orgs",
    "repos_url": "https://api.github.com/users/camel2243/repos",
    "events_url": "https://api.github.com/users/camel2243/events{/privacy}",
    "received_events_url": "https://api.github.com/users/camel2243/received_events",
    "type": "User",
    "user_view_type": "public",
    "site_admin": false
  },
  "html_url": "https://github.com/camel2243/camel-blog-comments",
  "description": "Giscus comment for https://blog.camel2243.com/",
  "fork": false,
  "url": "https://api.github.com/repos/camel2243/camel-blog-comments",
  "forks_url": "https://api.github.com/repos/camel2243/camel-blog-comments/forks",
  "keys_url": "https://api.github.com/repos/camel2243/camel-blog-comments/keys{/key_id}",
  "collaborators_url": "https://api.github.com/repos/camel2243/camel-blog-comments/collaborators{/collaborator}",
  "teams_url": "https://api.github.com/repos/camel2243/camel-blog-comments/teams",
  "hooks_url": "https://api.github.com/repos/camel2243/camel-blog-comments/hooks",
  "issue_events_url": "https://api.github.com/repos/camel2243/camel-blog-comments/issues/events{/number}",
  "events_url": "https://api.github.com/repos/camel2243/camel-blog-comments/events",
  "assignees_url": "https://api.github.com/repos/camel2243/camel-blog-comments/assignees{/user}",
  "branches_url": "https://api.github.com/repos/camel2243/camel-blog-comments/branches{/branch}",
  "tags_url": "https://api.github.com/repos/camel2243/camel-blog-comments/tags",
  "blobs_url": "https://api.github.com/repos/camel2243/camel-blog-comments/git/blobs{/sha}",
  "git_tags_url": "https://api.github.com/repos/camel2243/camel-blog-comments/git/tags{/sha}",
  "git_refs_url": "https://api.github.com/repos/camel2243/camel-blog-comments/git/refs{/sha}",
  "trees_url": "https://api.github.com/repos/camel2243/camel-blog-comments/git/trees{/sha}",
  "statuses_url": "https://api.github.com/repos/camel2243/camel-blog-comments/statuses/{sha}",
  "languages_url": "https://api.github.com/repos/camel2243/camel-blog-comments/languages",
  "stargazers_url": "https://api.github.com/repos/camel2243/camel-blog-comments/stargazers",
  "contributors_url": "https://api.github.com/repos/camel2243/camel-blog-comments/contributors",
  "subscribers_url": "https://api.github.com/repos/camel2243/camel-blog-comments/subscribers",
  "subscription_url": "https://api.github.com/repos/camel2243/camel-blog-comments/subscription",
  "commits_url": "https://api.github.com/repos/camel2243/camel-blog-comments/commits{/sha}",
  "git_commits_url": "https://api.github.com/repos/camel2243/camel-blog-comments/git/commits{/sha}",
  "comments_url": "https://api.github.com/repos/camel2243/camel-blog-comments/comments{/number}",
  "issue_comment_url": "https://api.github.com/repos/camel2243/camel-blog-comments/issues/comments{/number}",
  "contents_url": "https://api.github.com/repos/camel2243/camel-blog-comments/contents/{+path}",
  "compare_url": "https://api.github.com/repos/camel2243/camel-blog-comments/compare/{base}...{head}",
  "merges_url": "https://api.github.com/repos/camel2243/camel-blog-comments/merges",
  "archive_url": "https://api.github.com/repos/camel2243/camel-blog-comments/{archive_format}{/ref}",
  "downloads_url": "https://api.github.com/repos/camel2243/camel-blog-comments/downloads",
  "issues_url": "https://api.github.com/repos/camel2243/camel-blog-comments/issues{/number}",
  "pulls_url": "https://api.github.com/repos/camel2243/camel-blog-comments/pulls{/number}",
  "milestones_url": "https://api.github.com/repos/camel2243/camel-blog-comments/milestones{/number}",
  "notifications_url": "https://api.github.com/repos/camel2243/camel-blog-comments/notifications{?since,all,participating}",
  "labels_url": "https://api.github.com/repos/camel2243/camel-blog-comments/labels{/name}",
  "releases_url": "https://api.github.com/repos/camel2243/camel-blog-comments/releases{/id}",
  "deployments_url": "https://api.github.com/repos/camel2243/camel-blog-comments/deployments",
  "created_at": "2025-02-25T18:27:13Z",
  "updated_at": "2025-02-25T18:27:13Z",
  "pushed_at": "2025-02-25T18:27:13Z",
  "git_url": "git://github.com/camel2243/camel-blog-comments.git",
  "ssh_url": "[email protected]:camel2243/camel-blog-comments.git",
  "clone_url": "https://github.com/camel2243/camel-blog-comments.git",
  "svn_url": "https://github.com/camel2243/camel-blog-comments",
  "homepage": null,
  "size": 0,
  "stargazers_count": 0,
  "watchers_count": 0,
  "language": null,
  "has_issues": true,
  "has_projects": true,
  "has_downloads": true,
  "has_wiki": true,
  "has_pages": false,
  "has_discussions": true,
  "forks_count": 0,
  "mirror_url": null,
  "archived": false,
  "disabled": false,
  "open_issues_count": 0,
  "license": null,
  "allow_forking": true,
  "is_template": false,
  "web_commit_signoff_required": false,
  "topics": [],
  "visibility": "public",
  "forks": 0,
  "open_issues": 0,
  "watchers": 0,
  "default_branch": "main",
  "temp_clone_token": null,
  "network_count": 0,
  "subscribers_count": 1
}

參考資料


Previous Post
[leetcode] 14. Longest Common Prefix
Next Post
[leetcode] 12. Roman to Integer