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