Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
725 views
in Technique[技术] by (71.8m points)

git - Create Github repository from API

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"
}"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

  1. Upper right corner, click User
  2. Settings
  3. Personal Access Tokens
  4. For scopes, select Repos.
  5. Create New Token.

For more details, click here and here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...