从API创建Github存储库 [英] Create Github repository from API
本文介绍了从API创建Github存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请提供使用API创建Github存储库的工作代码。
我尝试了以下不同版本:
curl'https://api.github.com/users/repos?client_id= myusername& client_secret = abcdefghijklmnopqrstuvwxyz1234567890abcd'
curl -u'myusername'https: //api.github.com/users/repos -d'{name:my-new-repo}'
但我总是得到以下错误:
{
\message \\ \\:\\Bad credentials \,
\documentation_url \:\https://developer.github.com/v3\
}
解决方案
以下作品:
(不含变量)
curl -H授权:令牌abcdefghijklmnopqrstuvwxyz1234567890abcd
--data'{name:name -foo}'https://api.github.com/user/repos
(含变量)
NAME ='name-foo'
TOK ='abcdefghijklmnopqrstuvwxyz1234567890abcd'
BASE ='https://api.github.com/ '
EXT ='user / repos'
URL = $ BASE $ EXT
curl -HAuthorization:token $ TOK--data{\name \:\\ \\$ NAME \}$ URL
可以使用个人存取令牌而不是 OAuth 。
$ b
YOUR_TOKEN
$ c> curl
命令的Authorization:token YOUR_TOKEN部分可以按如下方式获得。
- 点击右上角的用户
- 设置
- 个人访问令牌
- 对于范围,请选择 Repos
创建新标记 。
Please provide working code that creates a Github repository using the API.
I have tried different versions of the following:
curl 'https://api.github.com/users/repos?client_id= myusername&client_secret=abcdefghijklmnopqrstuvwxyz1234567890abcd'
curl -u 'myusername' https://api.github.com/users/repos -d '{"name":"my-new-repo"}'
But I always get the following error:
"{
\"message\": \"Bad credentials\",
\"documentation_url\": \"https://developer.github.com/v3\"
}"
解决方案
The following works:
(without variables)curl -H "Authorization: token abcdefghijklmnopqrstuvwxyz1234567890abcd"
--data '{"name":"name-foo"}' https://api.github.com/user/repos
(with variables)
NAME='name-foo'
TOK='abcdefghijklmnopqrstuvwxyz1234567890abcd'
BASE='https://api.github.com/'
EXT='user/repos'
URL=$BASE$EXT
curl -H "Authorization: token $TOK" --data "{\"name\":\"$NAME\"}" $URL
One can use personal access tokens instead of OAuth.
The YOUR_TOKEN
value in the "Authorization: token YOUR_TOKEN"
section of the curl
command can be obtained as follows.
- Upper right corner, click User
- Settings
- Personal Access Tokens
- For scopes, select Repos.
- Create New Token.
For more details, click here and here.
这篇关于从API创建Github存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文