为什么不能用github api创建一个新的repo?

时间:2018-06-10 13:43:59

标签: github

我已经创建了一个令牌,因为这里有github api手册。

create a token

mytoken="xxxx"
curl -i -H "Authorization: token ${mytoken}" \
    https://api.github.com/user/repos

curl命令可以成功列出github中的所有repo。

使用github api创建一个新的公共仓库。

curl -i -H "Authorization: token ${mytoken}" \
    -d '{ \
        "name": "blog", \
        "auto_init": true, \
        "private": false, \
        "gitignore_template": "nanoc" \
      }' \
    https://api.github.com/user/repos

使用"private": true,创建私人仓库是没有用的。

curl命令的错误消息。

HTTP/1.1 400 Bad Request
Date: Mon, 11 Jun 2018 08:05:37 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 113
Server: GitHub.com
Status: 400 Bad Request
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4984
X-RateLimit-Reset: 1528705761
X-OAuth-Scopes: admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion
X-Accepted-OAuth-Scopes: public_repo, repo
X-GitHub-Media-Type: github.v3; format=json
Access-Control-Expose-Headers: ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
Access-Control-Allow-Origin: *
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
X-Frame-Options: deny
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
Content-Security-Policy: default-src 'none'
X-Runtime-rack: 0.030100
X-GitHub-Request-Id: B6F2:2195:194110:222B23:5B1E2D50

{
  "message": "Problems parsing JSON",
  "
documentation_url": "https://developer.github.com/v3/repos/#create"
}

1 个答案:

答案 0 :(得分:-1)

我找到的解决方法如下:

 curl -i -H "Authorization: token ${mytoken}" \
    -d '{ \
        "name": "blog" \
      }' \
    https://api.github.com/user/repos