常用的github-api分享

分享几个常用的github-api。

1.查询项目最新提交信息

以我的github项目为例,api完整链接如下。

https://api.github.com/repos/momodiy/sudoku/commits?per_page=10&sha=master

可选参数

  • per_page 查询条数
  • sha 查询分支

想要查询你自己的项目,只需将momodiy替换成你要查询的用户id,sudoku替换成你要查询的该用户的项目即可。

2.查询用户基本信息

依旧是以我的github账户为例,可查看用户的详细信息,返回信息如下json。

https://api.github.com/users/momodiy

{
  "login": "momodiy",
  "id": 20580248,
  "node_id": "MDQ6VXNlcjIwNTgwMjQ4",
  "avatar_url": "https://avatars1.githubusercontent.com/u/20580248?v=4",
  "gravatar_id": "",
  "url": "https://api.github.com/users/momodiy",
  "html_url": "https://github.com/momodiy",
  "followers_url": "https://api.github.com/users/momodiy/followers",
  "following_url": "https://api.github.com/users/momodiy/following{/other_user}",
  "gists_url": "https://api.github.com/users/momodiy/gists{/gist_id}",
  "starred_url": "https://api.github.com/users/momodiy/starred{/owner}{/repo}",
  "subscriptions_url": "https://api.github.com/users/momodiy/subscriptions",
  "organizations_url": "https://api.github.com/users/momodiy/orgs",
  "repos_url": "https://api.github.com/users/momodiy/repos",
  "events_url": "https://api.github.com/users/momodiy/events{/privacy}",
  "received_events_url": "https://api.github.com/users/momodiy/received_events",
  "type": "User",
  "site_admin": false,
  "name": "Steven Lee",
  "company": null,
  "blog": "momodiy.github.io",
  "location": null,
  "email": null,
  "hireable": true,
  "bio": "better me",
  "public_repos": 15,
  "public_gists": 0,
  "followers": 2,
  "following": 13,
  "created_at": "2016-07-21T13:57:31Z",
  "updated_at": "2018-07-02T12:28:42Z"
}

3.获取用户followers列表

https://api.github.com/users/momodiy/followers

想查看其他用户的只需将momodiy替换成你需要查看的用户id即可。

4.获取用户following列表

https://api.github.com/users/momodiy/following

想查看其他用户的只需将momodiy替换成你需要查看的用户id即可。

5.获取用户stared项目列表

https://api.github.com/users/momodiy/starred

想查看其他用户的只需将momodiy替换成你需要查看的用户id即可。

idea来自github中官方vue项目~

END

回复@freeframstye的评论

https://developer.github.com/v3/activity/watching/第一条API的用法为例。

一、列出观察者

返回一个数组,包含每一个对该项目watch的用户列表。

1.语法

GET /repos/:owner/:repo/subscribers

完整api为https://api.github.com拼接上文档中给出的url

2.关键参数

  • :owner 替换为项目作者
  • :repo 替换为项目名称

3.demo

https://api.github.com/repos/momodiy/sudoku/subscribers

你可能感兴趣的:(github)