Created
June 11, 2020 14:38
-
-
Save anchitarnav/2da3caa5ea73a310d23cb6a0911fae35 to your computer and use it in GitHub Desktop.
GCP API call using a credential file for a service account
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
# Doing an API call using some service account credentials | |
API_TO_HIT = "https://apikeys.googleapis.com/v2alpha1/projects/your-project-name/keys" | |
from google.auth.transport.requests import AuthorizedSession | |
from google.oauth2 import service_account | |
credentials = service_account.Credentials.from_service_account_file( | |
filename='/path/to/your_service_account_creds.json', | |
scopes=['https://www.googleapis.com/auth/cloud-platform'] | |
) | |
session = AuthorizedSession(credentials) | |
res = session.get(API_TO_HIT) | |
print(res, res.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment