Skip to content

Instantly share code, notes, and snippets.

@imduffy15
Created September 4, 2013 03:51
Show Gist options
  • Select an option

  • Save imduffy15/6432586 to your computer and use it in GitHub Desktop.

Select an option

Save imduffy15/6432586 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import httplib2
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import run
from apiclient.discovery import build
CLIENT_SECRETS = 'client_secrets.json'
OAUTH2_STORAGE = 'oauth2.dat'
GCE_SCOPE = 'https://localhost:5000'
API_VERSION = 'v1beta15'
GCE_URL = 'https://localhost:5000'
def main():
# Perform OAuth 2.0 authorization.
flow = flow_from_clientsecrets(CLIENT_SECRETS, scope=GCE_SCOPE)
storage = Storage(OAUTH2_STORAGE)
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = run(flow, storage)
http = httplib2.Http(disable_ssl_certificate_validation=True)
auth_http = credentials.authorize(http)
gce_service = build('compute', API_VERSION)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment