Github API V3在我尝试创建仓库时返回404错误

3
我执行了以下命令,并得到了相应的响应。但是,如果我尝试获取有关/user的信息,则可以正常工作,这意味着我的令牌是有效的。
我做错了什么?
guto@willie:~/$ curl -v -XPOST -H 'Authorization: token S3CR3T' -H 'Content-Type: application/json; charset=utf-8'  https://api.github.com/user/repos -d '{"name":"my-new-repo","description":"my new repo description"}'

输出:

* About to connect() to api.github.com port 443 (#0)
*   Trying 207.97.227.243... connected
* Connected to api.github.com (207.97.227.243) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using AES256-SHA
* Server certificate:
*    subject: O=*.github.com; OU=Domain Control Validated; CN=*.github.com
*    start date: 2009-12-11 05:02:36 GMT
*    expire date: 2014-12-11 05:02:36 GMT
*    subjectAltName: api.github.com matched
*    issuer: C=US; ST=Arizona; L=Scottsdale; O=GoDaddy.com, Inc.; OU=http://certificates.godaddy.com/repository; CN=Go Daddy Secure Certification Authority; serialNumber=07969287
*    SSL certificate verify ok.
> POST /user/repos HTTP/1.1
> User-Agent: curl/7.21.3 (x86_64-pc-linux-gnu) libcurl/7.21.3 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18
> Host: api.github.com
> Accept: */*
> Authorization: token S3CR3T
> Content-Type: application/json; charset=utf-8
> Content-Length: 62
> 
< HTTP/1.1 404 Not Found
< Server: nginx/1.0.4
< Date: Tue, 27 Dec 2011 03:45:12 GMT
< Content-Type: application/json; charset=utf-8
< Connection: keep-alive
< Status: 404 Not Found
< X-RateLimit-Limit: 5000
< ETag: "31b00b4920d3470b70611b10e0ba62a7"
< X-OAuth-Scopes: public_repo, user
< X-RateLimit-Remaining: 4976
< X-Accepted-OAuth-Scopes: repo
< Content-Length: 29
< 
{
  "message": "Not Found"
}
* Connection #0 to host api.github.com left intact
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):
guto@willie:~/projetos/apostilas/4linux-helper$ 
2个回答

2

请查看GitHub OAuth范围文档

$ curl -H "Authorization: bearer TOKEN" https://api.github.com/users/technoweenie -I
HTTP/1.1 200 OK
X-OAuth-Scopes: repo, user
X-Accepted-OAuth-Scopes: user

要创建一个repo,你需要拥有repo权限,这在SO问题“Github v3 API - create a REPO”中有说明。

repo

具备数据库读写权限,以及公共和私有代码仓库的Git读取权限。

注意:您的应用程序可以在初始重定向中请求所需的权限范围。
您可以通过逗号分隔多个权限范围来指定它们。

https://github.com/login/oauth/authorize?
  client_id=...&
  scope=user,public_repo

我知道,但是如果你看一下服务返回的头部信息,我已经在这些范围内注册了:<X-OAuth-Scopes: public_repo, user>。 - gutomaia
@gutomaia:没错,唯一的区别是使用“repo”而不是“public_repo”,但我猜你的账户只能管理公共仓库(而非私有仓库)。另一个可能的解释是某处存在类型错误或参数错误。 - VonC
很遗憾,参数没有任何问题。如果我使用无效的令牌访问,则服务会返回未经授权的错误。我真的不知道为什么。方法名称没问题,参数没问题,令牌没问题,甚至内容类型也没问题。还有什么问题?! - gutomaia
@gutomaia:你尝试在其他仓库上使用它了吗?或者让其他合作者在自己的仓库上尝试相同类型的命令? - VonC

1
尝试使用。
curl -v -X POST -H 'Content-Type: application/x-www-form-urlencoded' -d '{"name":"my-new-repo","description":"my new repo description"}' https://api.github.com/user/repos?access_token=S3CR3T

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接