Created
July 13, 2017 19:55
-
-
Save wejrowski/099de61593ce34695adf7e3dff81d42f to your computer and use it in GitHub Desktop.
Get google auth tokens from json
This file contains hidden or 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
# python auth.py /path/to/creds.json | |
# To install | |
# brew install python | |
# gcloud components install app-engine-python | |
# pip install --upgrade google-api-python-client | |
import sys | |
import json | |
import httplib2 | |
import os | |
from oauth2client.service_account import ServiceAccountCredentials | |
if sys.argv < 2: | |
print "Usage auth [path-to-json]" | |
else: | |
keyPath = sys.argv[1] | |
print "Using key from path " + keyPath | |
if not os.path.exists(keyPath): | |
print "Invalid path" | |
else: | |
jsonFile = open(keyPath, "r") | |
keyJson = json.load(jsonFile) | |
creds=ServiceAccountCredentials.from_json_keyfile_dict(keyJson, 'email') | |
http=httplib2.Http() | |
creds.refresh(http) | |
print creds.access_token |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment