這學(xué)期打算做一個(gè)關(guān)于 GitHub 的 Android 應(yīng)用,其中一個(gè)模塊就是查看 GitHub 當(dāng)天捡遍,當(dāng)周慕趴,當(dāng)月的熱門項(xiàng)目和開(kāi)發(fā)者。其實(shí) GitHub 給了開(kāi)發(fā)者相當(dāng)豐富的 API 接口 https://developer.github.com/v3/弱卡,包括認(rèn)證,搜索住册,活動(dòng)等接口婶博,但就是沒(méi)有提供獲取 Trending 的接口。去 GitHub Trending 的主頁(yè)看了一下荧飞,并看了其 html 代碼凡人,發(fā)現(xiàn)想要的東西都可以用爬蟲(chóng)爬去下來(lái),于是就著手爬去信息叹阔。
以下所有請(qǐng)求都為get請(qǐng)求,請(qǐng)求主地址為https://trendings.herokuapp.com
獲取熱門項(xiàng)目
路徑
/repo
參數(shù)
名稱 | 類型 | 描述 |
---|---|---|
lang | 字符串 | 可選挠轴,熱門項(xiàng)目的語(yǔ)言 |
since | 字符串 | 可選,get請(qǐng)求參數(shù)耳幢,無(wú)這參數(shù)則自動(dòng)獲取當(dāng)天的熱門項(xiàng)目岸晦,參數(shù)值只有三個(gè),分別是daily,weekly,monthly睛藻。 |
例如請(qǐng)求 https://trendings.herokuapp.com/repo?lang=java&since=weekly
返回結(jié)果:
//status code: 201
{
"count": 25,
"msg": "done",
//項(xiàng)目集合
"items": [
{
//項(xiàng)目貢獻(xiàn)者的頭像地址集合
"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"
],
//項(xiàng)目的地址
"repo_link": "https://github.com/kdn251/interviews",
//項(xiàng)目描述
"desc": "Everything you need to know to get the job.",
//項(xiàng)目倉(cāng)庫(kù)
"repo": "kdn251/interviews",
//目前為止的的stars數(shù)
"stars": "5,772",
//目前為止的forks數(shù)
"forks": "539",
//項(xiàng)目所屬語(yǔ)言
"lang": "Java",
//今天或者這周或者這個(gè)月的starts數(shù)
"added_stars": "4,591 stars this week"
},
.
.
.
]
}
獲取熱門開(kāi)發(fā)者
路徑
/developer
參數(shù)
名稱 | 類型 | 描述 |
---|---|---|
lang | 字符串 | 可選启上,熱門開(kāi)發(fā)者使用的主要語(yǔ)言 |
since | 字符串 | 可選,get請(qǐng)求參數(shù)店印,無(wú)這參數(shù)則自動(dòng)獲取當(dāng)天的熱門開(kāi)發(fā)者冈在,參數(shù)值只有三個(gè),分別是daily,weekly,monthly按摘。 |
請(qǐng)求 https://trendings.herokuapp.com/developer?lang=java&since=weekly
返回結(jié)果:
//status code: 201
{
"count": 25,
"msg": "done",
//開(kāi)發(fā)者集合
"items": [
{
//開(kāi)發(fā)者在GitHub上的用戶名
"user": "google",
//開(kāi)發(fā)者在GitHub上的主頁(yè)鏈接
"user_link": "https://github.com/google",
//開(kāi)發(fā)者的全名
"full_name": "(Google)",
// 開(kāi)發(fā)者的頭像地址
"developer_avatar": "https://avatars1.githubusercontent.com/u/1342004?v=3&s=96"
},
.
.
.
]
}
獲 取GitHub 上的所有 trending 語(yǔ)言包券。
請(qǐng)求地址:https://trendings.herokuapp.com/lang
返回結(jié)果:
//status code: 201
{
"count": 464,
"items": [
"1C-Enterprise",
"ABAP",
"ABNF",
"ActionScript",
"Ada",
.
.
.
"YANG",
"Zephir",
"Zimpl"
],
"msg": "suc"
}
異常
有時(shí)候去訪問(wèn) GitHub 的 trending 時(shí),會(huì)找不到熱門項(xiàng)目或者開(kāi)發(fā)者的,這時(shí)就會(huì)返回如下的 JSON:
//status code: 404
{
"msg": "Unavialiable.",
"count":0,
"items": []
}
維護(hù)
若某個(gè)接口無(wú)法調(diào)用,請(qǐng)通過(guò)簡(jiǎn)信或者郵箱 doforce@126.com
與我取得聯(lián)系炫贤,我會(huì)盡快修復(fù)問(wèn)題溅固。