我的组织中有一个私人仓库,我需要提供访问权限。我希望能够通过GET请求(浏览器)访问文件。我没有终端或卷曲或任何其他工具。
我创建了一个虚拟帐户,我链接到我的组织。我去了https://github.com/settings/tokens并加了一个。
然后我尝试了以下URL
这不起作用。它似乎只与您在github gui上单击“raw”时获得的生成令牌一起使用。不幸的是,此令牌很快就会过期,因此它不适用于我的应用程序。
如何通过URL使用访问令牌访问github上的私有资源?
API docs列表,您可以使用参数access_token
传入oauth令牌(而不是private_token
或token
)。
https://raw.githubusercontent.com/ORG/REPO/master/path/to/file.json?access_token=26cb4d8a30ca2能为你工作吗?
要获取原始用途:
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>