Created
April 13, 2020 09:19
-
-
Save iCorv/e70bd76844e9b6e3c95c9eb21669e82b to your computer and use it in GitHub Desktop.
How to generate google access tokens with a service account
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 google.auth | |
from google.auth.transport import requests | |
# check the scopes you need at https://developers.google.com/oauthplayground in the api list | |
SCOPES = ['https://www.googleapis.com/auth/devstorage.full_control'] | |
# env variable GOOGLE_APPLICATION_CREDENTIALS has to be set with service account key.json! | |
credentials, project_id = google.auth.default(scopes=SCOPES) | |
http_request = requests.Request() | |
def get_access_token(): | |
credentials.refresh(http_request) | |
return credentials.token |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment