【问题标题】:How to create a github.com repository over HTTP API?如何通过 HTTP API 创建 github.com 存储库?
【发布时间】:2015-08-27 12:28:20
【问题描述】:

根据general instruction to the github.com APIexplanation of the create command

curl -u "krichter722" https://api.github.com # works (returns JSON response)
curl -d '{"name":"test"}' https://api.github.com/user/repos/

应该可以工作并创建一个存储库,但是第二个命令失败了

{
  "message": "Not Found",
  "documentation_url": "https://developer.github.com/v3"
}

我找到了Using `curl` to create a repo on GitHub.com with two-factor authentication,它解决了由于双重身份验证请求中缺少部分而导致的问题。

其他问题,如"Bad Credentials" when attempting to create a GitHub repo through the CLI using curl,表明URL是正确的(在这种情况下,根据错误消息,由于凭据错误,创建失败)。

【问题讨论】:

    标签: github github-api


    【解决方案1】:

    你可以这样做:-

    curl -u "$username:$token" https://api.github.com/user/repos -d '{"name":"'$repo_name'"}'
    

    您可以在Github Settings -> Application 中找到个人访问令牌,将 username 替换为您的用户名,将 repo_name 替换为存储库名称。

    注意:- 如果您之前没有使用过个人访问令牌,您可能需要创建它。

    【讨论】:

    • 这是 github.com 的登录密码,而不是 $token,创建令牌的链接是 github.com/settings/tokens。文档读起来像是需要先进行身份验证,然后请求 API URL,但诀窍是使用 -u-d 选项调用 curl。确认也可以使用pythonrequest 模块。
    猜你喜欢
    • 1970-01-01
    • 2015-04-07
    • 2015-06-21
    • 1970-01-01
    • 2017-07-05
    • 2022-06-23
    • 1970-01-01
    • 2016-02-27
    • 1970-01-01
    相关资源
    最近更新 更多