6

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.

Max
  • 2,063
  • 2
  • 17
  • 16

1 Answers1

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.

Kevin Sawicki
  • 3,002
  • 1
  • 20
  • 18
  • In that case, as I menationed previously, you will post gist as Anonymous. Which is not the case. – Max May 14 '12 at 09:35
  • 1
    What do you see for the values of the headers I mentioned when you run your command "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" with the -v curl argument? – Kevin Sawicki May 14 '12 at 16:05
  • Alternatively you can check `curl -u "username:password" https://api.github.com/authorizations`, if it has "gists" in the scopes array – varesa Jul 17 '12 at 20:57