Skip to content

Instantly share code, notes, and snippets.

@wejrowski
Created July 13, 2017 19:54
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/e9f8e0e0d47b4e5afaea30aed53a760d to your computer and use it in GitHub Desktop.
Save wejrowski/e9f8e0e0d47b4e5afaea30aed53a760d to your computer and use it in GitHub Desktop.
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