Last active
May 19, 2021 00:24
-
-
Save davisagli/1128383064b1ba5c06b4 to your computer and use it in GitHub Desktop.
authenticating to google API using Service Account credentials
This file contains 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 httplib2 | |
# these are from the google-api-python-client package | |
from apiclient.discovery import build | |
from oauth2client.client import SignedJwtAssertionCredentials | |
def _get_google_service(email, key): | |
"""Get a Google API client using Service Account credentials""" | |
credentials = SignedJwtAssertionCredentials( | |
email, key, scope='https://www.googleapis.com/auth/analytics.readonly') | |
http = httplib2.Http() | |
http = credentials.authorize(http) | |
service = build('analytics', 'v3', http=http) | |
return service |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment