这学期打算做一个关于 GitHub 的 Android 应用,其中一个模块就是查看 GitHub 当天,当周,当月的热门项目和开发者。其实 GitHub 给了开发者相当丰富的 API 接口 ,包括认证,搜索,活动等接口,但就是没有提供获取 Trending 的接口。去 GitHub 的主页看了一下,并看了其 html 代码,发现想要的东西都可以用爬虫爬去下来,于是就着手爬去信息。
以下所有请求都为get请求,请求主地址为https://trendings.herokuapp.com
获取热门项目
路径
/repo
参数
名称 | 类型 | 描述 |
---|---|---|
lang | 字符串 | 可选,热门项目的语言 |
since | 字符串 | 可选,get请求参数,无这参数则自动获取当天的热门项目,参数值只有三个,分别是daily,weekly,monthly。 |
例如请求 https://trendings.herokuapp.com/repo?lang=java&since=weekly
返回结果:
//status code: 201{ "count": 25, "msg": "done", //项目集合 "items": [ { //项目贡献者的头像地址集合 "avatars": [ "https://avatars0.githubusercontent.com/u/16903644?v=3&s=40", "https://avatars2.githubusercontent.com/u/8622362?v=3&s=40", "https://avatars0.githubusercontent.com/u/10773353?v=3&s=40", "https://avatars3.githubusercontent.com/u/6392550?v=3&s=40", "https://avatars1.githubusercontent.com/u/3837836?v=3&s=40" ], //项目的地址 "repo_link": "https://github.com/kdn251/interviews", //项目描述 "desc": "Everything you need to know to get the job.", //项目仓库 "repo": "kdn251/interviews", //目前为止的的stars数 "stars": "5,772", //目前为止的forks数 "forks": "539", //项目所属语言 "lang": "Java", //今天或者这周或者这个月的starts数 "added_stars": "4,591 stars this week" }, . . . ]}复制代码
获取热门开发者
路径
/developer
参数
名称 | 类型 | 描述 |
---|---|---|
lang | 字符串 | 可选,热门开发者使用的主要语言 |
since | 字符串 | 可选,get请求参数,无这参数则自动获取当天的热门开发者,参数值只有三个,分别是daily,weekly,monthly。 |
请求 https://trendings.herokuapp.com/developer?lang=java&since=weekly
返回结果:
//status code: 201{ "count": 25, "msg": "done", //开发者集合 "items": [ { //开发者在GitHub上的用户名 "user": "google", //开发者在GitHub上的主页链接 "user_link": "https://github.com/google", //开发者的全名 "full_name": "(Google)", // 开发者的头像地址 "developer_avatar": "https://avatars1.githubusercontent.com/u/1342004?v=3&s=96" }, . . .]}复制代码
获 取GitHub 上的所有 trending 语言。
请求地址:https://trendings.herokuapp.com/lang
返回结果:
//status code: 201{ "count": 464, "items": [ "1C-Enterprise", "ABAP", "ABNF", "ActionScript", "Ada", . . . "YANG", "Zephir", "Zimpl" ], "msg": "suc"}复制代码
异常
有时候去访问 GitHub 的 trending 时,会找不到热门项目或者开发者的,这时就会返回如下的 JSON:
//status code: 404{ "msg": "Unavialiable.", "count":0, "items": []}复制代码
维护
若某个接口无法调用,请通过简信或者邮箱 doforce@126.com
与我取得联系,我会尽快修复问题。