Created
April 6, 2017 21:12
-
-
Save mxmader/8281851a99d0cfb53a363286246c08d8 to your computer and use it in GitHub Desktop.
Simple GitHub API example using python and personal access token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
#### | |
# inputs | |
#### | |
username = '' | |
# from https://github.com/user/settings/tokens | |
token = '' | |
repos_url = 'https://api.github.com/user/repos' | |
# create a re-usable session object with the user creds in-built | |
gh_session = requests.Session() | |
gh_session.auth = (username, token) | |
# get the list of repos belonging to me | |
repos = json.loads(gh_session.get(repos_url).text) | |
# print the repo names | |
for repo in repos: | |
print repo['name'] | |
# make more requests using "gh_session" to create repos, list issues, etc. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't work anymore. {'message': 'Bad credentials', 'documentation_url': 'https://docs.github.com/rest'}