Skip to content

Instantly share code, notes, and snippets.

@kmonsoor
Last active December 6, 2018 12:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmonsoor/d89c930a8df3060106c04648dc6058b0 to your computer and use it in GitHub Desktop.
Save kmonsoor/d89c930a8df3060106c04648dc6058b0 to your computer and use it in GitHub Desktop.
Python get_credential() for Google service_account() with *.json secret. ⭐ this gist if acts as useful, as a 👍
def get_credential_service_account():
from oauth2client.service_account import ServiceAccountCredentials
SERVICE_ACC_CREDENTIAL = 'your-service-account-secrets-file.json'
scopes = ['https://www.googleapis.com/auth/drive']
pprint("Request for credential received");
try:
credentials = ServiceAccountCredentials.from_json_keyfile_name(SERVICE_ACC_CREDENTIAL, scopes=scopes)
pprint(credentials)
return credentials
except Exception as e:
pprint("Failed to obtain valid credential")
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment