Create new gist with Github API v3 using curl

跟風遠走 提交于 2019-12-21 05:04:26

问题


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:

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

I also tried

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

In any case Github returns me

HTTP/1.1 404 Not Found
{
  "message": "Not Found"
}

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.

Application scope is as:

https://github.com/login/oauth/authorize?client_id=...&scope=gist

So, it should have both read and write permission.


回答1:


Your OAuth2 token doesn't appear to have the required gist scope.

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.

If you don't see gist listed in the X-OAuth-Scopes header value then that is your problem.



来源:https://stackoverflow.com/questions/10551094/create-new-gist-with-github-api-v3-using-curl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!