简体   繁体   中英

GitHub, creating new repository (Github API token)

I have written python scripts to list repositories and commits. To create a new repository, I have used the following code:

curl -F 'login=SolomonPeter26' -F 'token=mygithubapitoken' https://github.com/api/v2/json/repos/create -F 'name=REPONAME' -F 'description=This project is a test'

I can't access github API token of other users. So I couldn't write a python script for that sake.

Please suggest a better way to create such a new repository or a way to access the Github API token.( Can I get any help from oauth or oauth2)

I use Postman (a Chrome plug-ins). It can test success: 在此处输入图片说明

With the access_token , you can find personal access tokens of your account's setting.

There is a generic formula on Ritchie CLI to create a Github repository, using the user's Github API token.

Obs: The user will have to set the token manually the first time the command will be executed on the terminal (to save it locally).

Here are the code and the README file of this formula (in Python)

Here is an example of how it consumes the POST resource to create a repository with the Github API :

authorization = f'token {token}'
headers = {
    "Accept": "application/vnd.github.v3+json",
    "Authorization" : authorization,
    }

r = requests.post(
    url='https://api.github.com/user/repos',
    data=json_data,
    headers=headers
    )

As you can customize the commands using the tool, it is possible to automate many other operations with Github API the same way.

Yeah. You can't access API tokens of other users. It's same with twitter. You need to use Oauth2, and each user should get the API keys\\tokens and add them manually in the code. What you can do is provide an easy way for your users to add github API token.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM