使用curl创建使用Github API v3的新gist [英] Create new gist with Github API v3 using curl
问题描述
在战斗了相当一段时间后发布一个私人的github使用他们的API V3我几乎放弃了。几乎。可能有些人也面临类似的问题或者知道可能是以下行为的推理:
After fighting for quite some time for posting a private gist to Github using their API V3 I almost gave up. Almost. May be some one have also faced similar problem or know what might be the reasoning of the following behavior:
现在curl命令看起来像下面这样:
Right now the curl command looks like following:
curl -H "Authorization: bearer MY_AUTHORIZATION_TOKE" -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"public":false,"files":{"test.txt":{"content":"String file contents"}}}' https://api.github.com/gists
我也尝试了
curl -H "Authorization: bearer MY_AUTHORIZATION_TOKE" -X POST -d '{"public":false,"files":{"test.txt":{"content":"String file contents"}}}' https://api.github.com/gists
我可以使用完全相同的数据:
I am able to create gist without authorization token using exactly same data:
curl -X POST -d '{"public":true,"files":{"test.txt":{"content":"String file contents"}}}' https://api.github.com/gists
但在这种情况下它将是匿名的
But in that case it will be anonymous
如果我正在修改为公开发布,结果相同。
Same results if I am truing to post it as public
在任何情况下Github返回我
In any case Github returns me
HTTP/1.1 404 Not Found
{
"message": "Not Found"
}
, curl -H授权:bearer MY_AUTHORIZATION_TOKEhttps://api.github.com/user
返回我的用户详细信息。
I am pretty sure I am authorized, as curl -H "Authorization: bearer MY_AUTHORIZATION_TOKE" https://api.github.com/user
returns me my user details.
应用范围为:
https://github.com/login/oauth/authorize?client_id=...&scope=gist
推荐答案
您的OAuth2令牌似乎没有所需的 gist
范围。
Your OAuth2 token doesn't appear to have the required gist
scope.
如果您运行 curl
code> -v 参数您可以看到发送到请求的范围( X-OAuth-Scopes
头)
If you run the curl
commands with the -v
argument you can see the scope sent to request (X-OAuth-Scopes
header) and the scope required for the request (X-Accepted-OAuth-Scopes
header) to successfully be performed using the token sent.
如果您已成功使用发送的令牌执行请求( X-Accepted-OAuth- Scopes
没有看到 X-OAuth-Scopes
头值中列出的 gist
,那就是你的问题。
If you don't see gist
listed in the X-OAuth-Scopes
header value then that is your problem.
这篇关于使用curl创建使用Github API v3的新gist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!