【问题标题】:Github Api v3 giving 404 when I try to create a repo当我尝试创建存储库时,Github Api v3 给出 404
【发布时间】:2011-12-27 04:00:01
【问题描述】:

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

【问题讨论】:

    标签: api github


    【解决方案1】:

    查看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 范围才能有权创建 repo,如 SO 问题“Github v3 API - create a REPO”所示。

    repo
    

    DB 读/写访问权限,以及 Git 对公共和私有存储库的读取访问权限。

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

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

    【讨论】:

    • 我知道,但是如果您查看服务返回的标头。我已经在这些范围上注册了:
    • @gutomaia:是的,唯一的区别是'repo'而不是'public_repo',但我想你有一个仅用于管理公共回购(而不是私人回购)的帐户。唯一的其他解释是某处的某些类型/错误参数。
    • 很遗憾,参数没有问题。如果我使用无效的令牌访问,该服务会给出未经授权的错误。我真的不知道为什么。方法名称没问题,参数没问题,令牌也没问题,即使内容类型也没问题。还有什么?!
    • @gutomaia:您是否尝试过其他存储库。或者请其他合作者在他们自己的 repos 上尝试相同类型的命令?
    【解决方案2】:

    尝试使用

    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
    

    【讨论】:

      猜你喜欢
      • 2013-08-21
      • 2016-02-27
      • 2021-07-09
      • 2023-03-13
      • 2012-06-03
      • 2012-04-01
      • 1970-01-01
      • 2020-06-04
      • 1970-01-01
      相关资源
      最近更新 更多