-2

基本上,我想收集一个指向 github repos 的链接列表,并且能够在自述文件中浏览一个列表。有人知道这样做的吗?

4

1 回答 1

0

您可以使用GitHub 的 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 链接。但是由于您只想要文件的内容,因此您需要更改blobraw

$ curl "https://raw.github.com/octocat/Spoon-Knife/master/README"
All that's missing is the fork. Heh.

当然,您可能希望使用您正在使用的任何编程语言的 HTTP 工具,而不是curl查询 GitHub 服务器。

编辑

content您可以使用 base64 解码器对该字段进行解码,而不是发出额外的 GET 请求:

$ echo QWxsIHRoYXQncyBtaXNzaW5nIGlzIHRoZSBmb3JrLiBIZWgu | base64 --decode
All that's missing is the fork. Heh.
于 2012-11-03T17:03:37.097 回答