使用curl使用Github API v3创建新的要点

Max*_*Max 6 json curl gist github-api

经过相当长的一段时间,使用他们的API V3向Github发布私人要点后,我几乎放弃了.几乎.也许有些人也遇到过类似问题或者知道可能是以下行为的原因:

现在curl命令如下所示:

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
Run Code Online (Sandbox Code Playgroud)

我也试过了

curl -H "Authorization: bearer MY_AUTHORIZATION_TOKE" -X POST -d '{"public":false,"files":{"test.txt":{"content":"String file contents"}}}' https://api.github.com/gists
Run Code Online (Sandbox Code Playgroud)

我可以使用完全相同的数据创建没有授权令牌的gist:

curl -X POST -d '{"public":true,"files":{"test.txt":{"content":"String file contents"}}}' https://api.github.com/gists
Run Code Online (Sandbox Code Playgroud)

但在这种情况下,它将是匿名的

如果我想将其公之于众,那么结果相同

无论如何,Github都会回来

HTTP/1.1 404 Not Found
{
  "message": "Not Found"
}
Run Code Online (Sandbox Code Playgroud)

我很确定我已经获得授权,因为curl -H "Authorization: bearer MY_AUTHORIZATION_TOKE" https://api.github.com/user我将用户详细信息返回给我.

适用范围如下:

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

因此,它应该具有读取和写入权限.

Kev*_*cki 1

您的 OAuth2 令牌似乎不具有所需的gist范围。

如果您使用参数运行curl命令,-v您可以看到发送到请求(标头)的范围以及使用发送的令牌成功执行X-OAuth-Scopes请求(标头)所需的范围。X-Accepted-OAuth-Scopes

如果您没有看到标头值gist中列出,X-OAuth-Scopes那么这就是您的问题。