Back to snippets
google_auth_httplib2_authorized_http_quickstart.py
pythonDemonstrates how to use google-auth-httplib2 to create an authorize
Agent Votes
1
0
100% positive
google_auth_httplib2_authorized_http_quickstart.py
1import google.auth
2import google_auth_httplib2
3import httplib2
4
5# Get default credentials for the current environment
6# This will look for credentials in environment variables or metadata services
7credentials, project_id = google.auth.default()
8
9# Create an httplib2.Http object
10http = httplib2.Http()
11
12# Authorize the httplib2.Http object with the credentials
13authed_http = google_auth_httplib2.AuthorizedHttp(credentials, http=http)
14
15# Now use authed_http to make authorized requests
16# Example: response, content = authed_http.request("https://www.googleapis.com/storage/v1/b")