通过access_token在Github上的私人仓库中读取文件的原始内容 [英] Read Raw Contents of File in Private Repo on Github via access_token
问题描述
我正在尝试检索Github上私人存储库的README.rm文件的原始内容.
I am trying to retrieve the raw contents of the README.rm file of a private repository on Github.
我非常接近,当前唯一的问题是,我将获得401未经授权的结果.
I'm extremely close, the only issue currently, is that I'm getting back a 401 unauthorized result.
当前,我正在尝试使用以下方式检索文件:
Currently, I am trying to retrieve the file using:
$query = $this->config['raw_url'] . '/README.md?login=chriscct7&token='.$this->config['access_token'] ;
//$query = add_query_arg( array( 'access_token' => $this->config['access_token'] ), $query );
$query = $query.'&token_type=bearer';
$raw_response = wp_remote_get( $query, array( 'sslverify' => $this->config['sslverify'] ) );
var_dump($query, $raw_response);
这使得网址类似于 https://raw.github.com/chriscct7/Testplugin/master/README.md?login=chriscct7&token=e590999c1680dba1bcd5488658fa570ebebccbf53e&token_type=bearer
回邮:
array (size=5)
'headers' =>
array (size=16)
'date' => string 'Wed, 23 Jan 2013 13:58:50 GMT' (length=29)
'server' => string 'GitHub.com' (length=10)
'content-type' => string 'text/html; charset=utf-8' (length=24)
'status' => string '401 Unauthorized' (length=16)
'x-ratelimit-remaining' => string '100' (length=3)
'x-runtime' => string '12' (length=2)
'x-ratelimit-limit' => string '100' (length=3)
'content-length' => string '1' (length=1)
'accept-ranges' => string 'bytes' (length=5)
'age' => string '0' (length=1)
'via' => string '1.1 varnish' (length=11)
'x-served-by' => string 'cache-c32-CHI' (length=13)
'x-cache' => string 'MISS' (length=4)
'x-cache-hits' => string '0' (length=1)
'cache-control' => string 'no-cache' (length=8)
'connection' => string 'close' (length=5)
'body' => string ' ' (length=1)
'response' =>
array (size=2)
'code' => string '401' (length=3)
'message' => string 'Unauthorized' (length=12)
'cookies' =>
array (size=0)
empty
'filename' => null
访问令牌是使用提供的OAuth 示例制作的.我已经检查了,我在Github上的应用程序确实可以访问我的私有存储库.
The access token was made by using the provided OAuth example. I have checked, and my app on Github does have access to my private repositories.
现在,我知道我的方法可行,因为如果我使用个人登录令牌:
Now, I know my method works, because if I use my personal login token:
$query = 'https://raw.github.com/chriscct7/Testplugin/master/README.md?login=chriscct7&token=e4d293652a9081d79e582984a3f32dc7';
$raw_response = wp_remote_get( $query, array( 'sslverify' => $this->config['sslverify'] ) );
这有效,并且可以很好地返回文件的内容.请注意,出于安全原因,我没有在上面的代码中使用真实的令牌.
This works, and returns the contents of the file fine. Note I did not use my real tokens in the code above for security reasons.
但是,我需要使用应用程序的access_token进行这项工作.
However, I need to make this work using the app's access_token.
有什么想法吗?
推荐答案
需要使用回购内容API" .该文件的内容将包含在base64中,以及API的响应.
This needs to be handled using the Repo contents API provided by GitHub. The file content would be in base64, withing the API's response.
这篇关于通过access_token在Github上的私人仓库中读取文件的原始内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!