我熟悉GitHub API http://developer.github.com/v3/我正在尝试使用RESTClient插件和Firefox以及curl命令行工具 .
我已经了解了如何使用API创建repo,但是我似乎无法使用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
帮助没有指定,我不确定它们的含义:所有者和:repo - 这些是名称还是ID,但我尝试了几种名称和ID,但没有成功 . 我收到的回复是:
404 Not Found
我错过了什么?
3 回答
这是使用Apache Http Components(Java)的完整工作示例:
Delete Repository
curl -X DELETE -H 'Authorization: token {access token goes here}' https://api.github.com/repos/{yourUsername}/{name of repo}
替换里面的花括号和文字 .Display Header
curl -I https://api.github.com
-I
表示仅获取HTTP标头 .Create Repository
curl -u yourUsername -X POST https://api.github.com/user/repos -d '{"name":"nameOfRepo"}'
如果您通过Applications page创建了令牌,那么此令牌将包含scopes:
user
,public_repo
,repo
,gist
. 您可以通过使用该令牌发出API请求并查看响应HTTP标头来验证这一点:curl -v -H 'Authorization: token xxx' https://api.github.com
查找
X-OAuth-Scopes
响应标头,其中包含范围列表:X-OAuth-Scopes: user, public_repo, repo, gist
但是,要删除存储库,token needs to have the delete_repo scope .
因此,您需要一个与您拥有的范围不同的令牌 . 您可以使用Authorizations API创建此类令牌:
curl -v -u username -X POST https://api.github.com/authorizations -d '{"scopes":["delete_repo"], "note":"token with delete repo scope"}'
这将返回一个带有新令牌的JSON文档,您应该可以使用它来删除存储库:
当然,在以这种方式创建令牌时,您可以要求多个范围,而不仅仅是
delete_repo
范围 .此外,作为附注,当您没有正确的授权时,API返回404错误的原因是prevent information leakage .