Skip to content

Instantly share code, notes, and snippets.

@anchitarnav
Last active June 11, 2020 14:51
Show Gist options
  • Save anchitarnav/ecb6ced3de981266193b83d7e17c4cf5 to your computer and use it in GitHub Desktop.
Save anchitarnav/ecb6ced3de981266193b83d7e17c4cf5 to your computer and use it in GitHub Desktop.
Doing an Google Cloud Platform / GCP / GCLOUD API Call
API_TO_HIT = "https://apikeys.googleapis.com/v2alpha1/projects/your-project-id/keys"
from google.auth.transport.requests import AuthorizedSession
from google.auth import default
# Assuming GOOGLE_APPLICATION_CREDENTIALS env variable is set
credentials, default_project_id = default(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