Github v3 API - create a REPO

后端 未结 4 1022
心在旅途
心在旅途 2020-12-09 06:46

I’m trying to use the Github v3 API - I already implemented the required OAuth flow and it works well.

Now I’m trying some of the Repos API endpoints (http://develo

相关标签:
4条回答
  • 2020-12-09 07:38

    For creating repositories as a user you can use an personal access token and basic auth, which can be much simpler when you are fluffing around on the command line and have 2FA enabled.

    curl -d '{"name":"test"}' -u githubuser:personaccesstoken https://api.github.com/user/repos
    

    Create a personal access token here https://github.com/settings/tokens and make sure it has the 'repo' scope.

    0 讨论(0)
  • 2020-12-09 07:45

    Can you please tell us how exactly you did the HTTP request? The 404 sounds like you were using a wrong path, probably. But to give a reliable answer instead a wild guess, we need to see your request, including how you are sending your token, just mask it with 'xxx' or something.

    I'll show you in the meantime an example request, that is working:

    curl -XPOST -H 'Authorization: token S3CR3T' https://api.github.com/user/repos -d '{"name":"my-new-repo","description":"my new repo description"}'

    You would need to replace the OAuth token of course: S3CR3T

    0 讨论(0)
  • 2020-12-09 07:47

    This script lets you read in in the token and project name as variables so you can use it in a script

    #!/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
    
    0 讨论(0)
  • 2020-12-09 07:49

    I had the same issue. The reason why you are getting a 404 with your oauth access token is that when you authorize to github you need to also additionally pass the scopes you want. For example, in the header you should see "X-OAuth-Scopes: repo, user", which means this user has read/write access to his profile and repositories. Once you have set the correct scopes you should be able to do POST/PUT requests just fine.

    To see whether or not you have the correct permissions. You can do something like the following. Substitute the XXXXXXX with your access token.

    curl -I https://api.github.com/user?access_token=XXXXXXXX
    
    0 讨论(0)
提交回复
热议问题