GitHub API文件更新:"未找到"

mco*_*lin 3 api file-upload github fileupdate

我试图通过API更新我的一个回购文件中的文件.

这是我得到的那个文件(效果很好):

curl -XGET 'https://git.fake.local/api/v3/repos/jsmith/repo_version/contents/version.html?ref=gh-pages'
{
  "name": "version.html",
  "path": "version.html",
  "sha": "b1b716105590454bfc4c0247f193a04088f39c7f",
  "size": 5,
  "url": "https://git.fake.local/api/v3/repos/jsmith/post_version/contents/version.html?ref=gh-pages",
  "html_url": "https://git.fake.local/jsmith/post_version/blob/gh-pages/version.html",
  "git_url": "https://git.fake.local/api/v3/repos/jsmith/post_version/git/blobs/b1b716105590454bfc4c0247f193a04088f39c7f",
  "type": "file",
  "content": "aW5pdAo=\n",
  "encoding": "base64",
  "_links": {
    ...
  }
}
Run Code Online (Sandbox Code Playgroud)

这是我尝试通过PUT更新该文件:

curl -XPUT 'https://git.fake.local/api/v3/repos/jsmith/repo_version/contents/version.html?ref=gh-pages' -d '{
   "message": "update from api",
   "committer": {
     "name": "Joe Smith",
     "email": "jsmith@fake.com"
   },
   "content": "bXkgdXBkYXRlZCBmaWxlIGNvbnRlbnRz",
   "sha": "b1b716105590454bfc4c0247f193a04088f39c7f"
 }'
Run Code Online (Sandbox Code Playgroud)

结果:

{
  "message": "Not Found"
}
Run Code Online (Sandbox Code Playgroud)

mco*_*lin 5

好的......我想我明白了.

来自github doco:

认证

有三种方法可以通过GitHub API v3进行身份验证.需要身份验证的请求将返回404 Not Found,而不是403 Forbidden在某些地方.这是为了防止私有存储库意外泄露给未经授权的用户.

如果Auth是一个问题,我期待403,但他们扔了404,所以基本上我可能需要确保我正确认证,一切都会好.

已解决:我创建了一个个人oauth令牌(在设置/应用程序下)并添加到标题中的curl请求,这一切都很有效.

curl -XPUT -H "Authorization: token MYSECRETTOKEN"