我正在尝试使用Github v3 API - 我已经实现了必要的OAuth流程并且它工作得很好。现在我正在尝试一些Repos API端点(http://developer.github.com/v3/repos/)。到目前为止,我能够使用GET /user/repos获取我的repos列表,但是当我尝试使用POST /user/repos创建一个repo时,我会得到一个404错误。你认为我可能做错了什么?
curl -XPOST -H 'Authorization: token S3CR3T' https://api.github.com/user/repos -d '{"name":"my-new-repo","description":"my new repo description"}'
当然,您需要替换OAuth令牌:S3CR3T
。curl -I https://api.github.com/user?access_token=XXXXXXXX
作为用户创建存储库时,您可以使用个人访问令牌和基本身份验证。当您在命令行上操作并启用了2FA时,这可能会更加简单。
curl -d '{"name":"test"}' -u githubuser:personaccesstoken https://api.github.com/user/repos
这个脚本允许你将令牌和项目名称作为变量读入,以便在脚本中使用。
#!/usr/bin/env bash -u
#
TOKEN=`cat token_file`
PROJECT=myproject
curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -d '{"name": "'"$PROJECT"'"}' https://api.github.com/user/repos?access_token=$TOKEN