Github使用访问令牌

时间:2016-10-03 08:39:56

标签: git github

我的组织中有一个私人仓库,我需要提供访问权限。我希望能够通过GET请求(浏览器)访问文件。我没有终端或卷曲或任何其他工具。

我创建了一个与我的组织关联的虚拟帐户。我去了https://github.com/settings/tokens并添加了一个。

然后我尝试了以下网址

哪个不起作用。它似乎只适用于您单击" raw"时生成的令牌。在github gui。不幸的是,这个令牌很快就会过期,所以它对我的应用程序不起作用。

如何通过URL访问github上的私有资源?

2 个答案:

答案 0 :(得分:5)

API docs列表,您可以使用参数private_token传入oauth令牌(不是token或{{1}})。

https://raw.githubusercontent.com/ORG/REPO/master/path/to/file.json?access_token=26cb4d8a30ca2是否适合您?

答案 1 :(得分:0)

获取原始用途:

curl \
  -H 'Authorization: token <personal token gen value>' \
  https://raw.<host>/user/org/repo/pathtofile

通过api获取:

curl \
  -H 'Authorization: token <personal token gen>' \
  -H 'Accept:application/vnd.github.VERSION.raw' \
  https://<host_name>/api/v3/repos/<user>/<repo_name>/contents/<path_to_file>/?ref=<branch>