Github开放Api使用总结
api文档
有rest ful和graphql两种风格的api,不需要授权的api可以直接在浏览器中打开,对于需要授权的api,授权方式可以参考,另外调用API的频率有一定限制。
users
获取自己的信息:https://api.github.com/users/JackFei
获取自己的仓库信息列表:https://api.github.com/users/JackFei/repos
获取follow自己的用户信息列表:https://api.github.com/users/JackFei/followers
获取自己follow的用户列表:https://api.github.com/users/JackFei/following
获取自己star的仓库列表:https://api.github.com/users/JackFei/starred
获取自己的组织列表:https://api.github.com/users/JackFei/orgs
判断自己是否关注某个人:https://api.github.com/users/JackFei/following/rauchg
判断自己是否star某个仓库:https://api.github.com/users/JackFei/starred/ruanyf/articles
repos
获取repo的内容列表:https://api.github.com/repos/solomonxie/gists/contents
获取repo中子目录的内容列表:https://api.github.com/repos/solomonxie/gists/contents/目录名
获取repo中某文件信息(不包括内容):https://api.github.com/repos/solomonxie/gists/contents/文件路径
获取某文件的原始内容(Raw):1
2通过上面的文件信息中提取download_url这条链接,就能获取它的原始内容了
或者直接访问:https://raw.githubusercontent.com/用户名/仓库名/分支名/文件路径
获取repo中所有的commits列表:https://api.github.com/repos/用户名/仓库名/commits
获取某条commit详情:https://api.github.com/repos/用户名/仓库名/commits/某一条commit的SHA
Issues
获取issues列表:https://api.github.com/repos/JackFei/WebIssues/issues
获取某条issue详情:https://api.github.com/repos/JackFei/WebIssues/issues/1
获取某条issue中的comments列表:https://api.github.com/repos/JackFei/WebIssues/issues/1/comments
获取某条comments详情:https://api.github.com/repos/JackFei/WebIssues/issues/comments/440704176
创建一条issue:https://api.github.com/repos/JackFei/WebIssues/issues,POST方法,需要token,参数如下:1
2
3
4{
"title": "Creating issue from API",
"body": "Posting a issue from Insomnia"
}
锁住某条issue不允许别人评论:https://api.github.com/repos/JackFei/WebIssues/issues/10/lock,PUT方法,需要token,参数如下:1
2
3
4{
"locked": true,
"active_lock_reason": "too heated"
}
解锁某条issue:https://api.github.com/repos/JackFei/WebIssues/issues/10/lock,DELETE方法,无参数,需要token认证
在issue中添加comments:https://api.github.com/repos/JackFei/WebIssues/issues/10/comments,POST方法,需要token认证,参数如下:1
2
3{
"body": "Create a comment from API"
}
Organizations
获取组织信息:https://api.github.com/orgs/tencent
获取组织下的仓库信息:https://api.github.com/orgs/tencent/repos
获取组织的events:https://api.github.com/orgs/tencent/events
获取组织下的成员:https://api.github.com/orgs/tencent/members
获取组织public成员:https://api.github.com/orgs/tencent/public_members
Search
搜索仓库:https://api.github.com/search/repositories?q=react&sort=stars&order=desc
搜索code:https://api.github.com/search/code?q=addClass+in:file+language:js+repo:jquery/jquery
搜索issues:https://api.github.com/search/issues?q=windows+label:bug+language:python+state:open&sort=created&order=asc
搜索users:https://api.github.com/search/users?q=tom+repos:%3E42+followers:%3E1000
Teams
Projects
用户的projects:https://api.github.com/users/JackFei/projects
组织的projects:https://api.github.com/orgs/tencent/projects
仓库的projects:https://api.github.com/repos/BestResume/projects
注意事项
1.{}括号参数主要用户判断是否进行了某项操作,如下实例:
https://api.github.com/users/torvalds/following{/other_user}
https://api.github.com/users/JackFei/starred{/owner}{/repo}
2.测试带有token的api,可以使用postman
3.可以安装iFormatTool浏览器插件,方便查看接口返回数据
参考博客
1.https://segmentfault.com/a/1190000015144126
2.基于taro的微信小程序