github-api - 如何使用 API 删除 GitHub 存储库

标签 github-api

我正在熟悉 GitHub API http://developer.github.com/v3/我正在尝试使用 Firefox 的 RESTClient 插件和curl 命令行工具。

我已经找到了如何使用 API 创建存储库,但我似乎无法使用 API 删除它。

根据这里的帮助:http://developer.github.com/v3/repos/#delete-a-repository我必须发送这样的 DELETE 请求:

curl -X DELETE -H 'Authorization: token xxx' https://api.github.com/repos/:owner/:repo

帮助没有指定,我不确定 :owner 和 :repo 的含义 - 这些是名称还是 id,但我尝试了几种组合的名称和 id,但没有成功。我收到的回复是:

404 Not Found

我错过了什么?

最佳答案

如果您通过Applications page创建了您正在使用的 token ,那么这个 token 将有这些 scopes :用户public_reporepo要点。您可以通过使用该 token 发出 API 请求并查看响应 HTTP header 来验证这一点:

curl -v -H '授权: token xxx' https://api.github.com

查找 X-OAuth-Scopes 响应 header ,其中包含范围列表:

X-OAuth-范围:用户、public_repo、repo、gist

但是,要删除存储库,token needs to have the delete_repo scope .

因此,您需要一个与您现有的 token 具有不同范围的 token 。您可以使用 Authorizations API 创建这样的 token :

curl -v -u 用户名 -X POST https://api.github.com/authorizations -d '{"scopes":["delete_repo"], "note":"具有删除存储库范围的 token “}'

这将返回一个带有新 token 的 JSON 文档,您应该能够使用它来删除存储库:

{
  "id": XXXXX,
  "url": "https://api.github.com/authorizations/XXXXX",
  "app": {
    "name": "GitHub API",
    "url": "http://developer.github.com/v3/oauth/#oauth-authorizations-api",
    "client_id": "00000000000000000000"
  },
  "token": "XXXXXX",
  "note": "token with delete repo scope",
  "note_url": null,
  "created_at": "2013-10-11T20:34:49Z",
  "updated_at": "2013-10-11T20:34:49Z",
  "scopes": [
    "delete_repo"
  ]
}

当然,以这种方式创建 token 时,您可以请求多个范围,而不仅仅是 delete_repo 范围。

此外,作为旁注,当您没有正确的授权时,API 返回 404 错误的原因是 prevent information leakage .

关于github-api - 如何使用 API 删除 GitHub 存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19319516/

相关文章:

Jenkins GitHub 访问 token - 启用检查但不编写代码

GitHub API 对于单字节 ("0xC4") 二进制文件返回三个字节

ruby - 将 Github API 与 rest 客户端一起使用来创建文件

github-api - 有效地检索所有 GitHub 提交的统计信息

github - 我们如何知道使用 github 中的 API 批准或拒绝拉取请求?

javascript - MeteorJs - http 调用中出现错误

github - 在 GitHub 中搜索 fork 的存储库

github - 使用 GitHub API 如何在不遍历项目中的卡片的情况下找到链接到特定问题的卡片 ID?

github - 如何使用 Github 的 v4 GraphQL API 查询用户的评论请求?

github - 格里特和 GitHub。 com.googlesource.gerrit.plugins.github.oauth.OAuthFilter