基本上,我想收集github repos的链接列表,并且如果读取,可以浏览列表。有人知道有什么事吗?
答案 0 :(得分:0)
您可以使用GitHub's Web API。
我将使用Spoon-Knife repo:
进行演示首先,您提出获取自述文件的请求(当然,将octocat/Spoon-Knife
替换为您需要的用户名和重新命名):
$ curl "https://api.github.com/repos/octocat/Spoon-Knife/readme"
{
"type": "file",
"html_url": "https://github.com/octocat/Spoon-Knife/blob/master/README",
"_links": {
"html": "https://github.com/octocat/Spoon-Knife/blob/master/README",
"git": "https://api.github.com/repos/octocat/Spoon-Knife/git/blobs/c8f68c2fd5a340b5ec89ada61984254e31c6785d",
"self": "https://api.github.com/repos/octocat/Spoon-Knife/contents/README"
},
"url": "https://api.github.com/repos/octocat/Spoon-Knife/contents/README",
"path": "README",
"git_url": "https://api.github.com/repos/octocat/Spoon-Knife/git/blobs/c8f68c2fd5a340b5ec89ada61984254e31c6785d",
"content": "QWxsIHRoYXQncyBtaXNzaW5nIGlzIHRoZSBmb3JrLiBIZWgu\n",
"sha": "c8f68c2fd5a340b5ec89ada61984254e31c6785d",
"encoding": "base64",
"size": 36,
"name": "README"
}
注意html_url
字段 - 这是GitHub Web-GUI显示中文件的HTML链接。但由于您只需要文件内容,因此您需要将blob
更改为raw
:
$ curl "https://raw.github.com/octocat/Spoon-Knife/master/README"
All that's missing is the fork. Heh.
当然,您可能希望使用您使用的任何编程语言的HTTP工具而不是curl
来查询GitHub服务器。
修改强>
您可以使用base64解码器解码content
字段,而不是发出额外的GET请求:
$ echo QWxsIHRoYXQncyBtaXNzaW5nIGlzIHRoZSBmb3JrLiBIZWgu | base64 --decode
All that's missing is the fork. Heh.