Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@wejrowski
Created July 13, 2017 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wejrowski/099de61593ce34695adf7e3dff81d42f to your computer and use it in GitHub Desktop.
Save wejrowski/099de61593ce34695adf7e3dff81d42f to your computer and use it in GitHub Desktop.
Get google auth tokens from json
# 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