当我尝试创建一个回购时,Github Api v3给出了404

时间:2011-12-27 04:00:02

标签: api github

我已经用相应的响应执行了以下命令 但是,如果我尝试获取有关/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 个答案:

答案 0 :(得分:2)

检查Oath Scope GitHub documentation

$ 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 范围才能拥有创建回购的权利,如SO问题“Github v3 API - create a REPO”所示。

repo
  

数据库读/写访问,以及对公共和私有存储库的Git读访问。

     

注意:您的应用程序可以在初始重定向中请求范围   您可以通过逗号分隔多个范围。

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

答案 1 :(得分: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