How to use the oauth2client.tools.run function in oauth2client

To help you get started, we’ve selected a few oauth2client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github egeldenhuys / csv-to-calendar / upload.py View on Github external
home_dir = os.path.expanduser('~')
    credential_dir = os.path.join(home_dir, '.credentials')
    if not os.path.exists(credential_dir):
        os.makedirs(credential_dir)
    credential_path = os.path.join(credential_dir,
                                   'calendar-python-quickstart.json')

    store = Storage(credential_path)
    credentials = store.get()
    if not credentials or credentials.invalid:
        flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
        flow.user_agent = APPLICATION_NAME
        if flags:
            credentials = tools.run_flow(flow, store, flags)
        else:  # Needed only for compatibility with Python 2.6
            credentials = tools.run(flow, store)
        print('Storing credentials to ' + credential_path)
    return credentials
github dguenms / Dawn-of-Civilization / Assets / Python / DownloadCityNameMaps.py View on Github external
home_dir = os.path.expanduser('~')
    credential_dir = os.path.join(home_dir, '.credentials')
    if not os.path.exists(credential_dir):
        os.makedirs(credential_dir)
    credential_path = os.path.join(credential_dir,
                                   'sheets.googleapis.com-python-quickstart.json')

    store = Storage(credential_path)
    credentials = store.get()
    if not credentials or credentials.invalid:
        flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
        flow.user_agent = APPLICATION_NAME
        if flags:
            credentials = tools.run_flow(flow, store, flags)
        else: # Needed only for compatibility with Python 2.6
            credentials = tools.run(flow, store)
        print('Storing credentials to ' + credential_path)
    return credentials
github aw-mfe / gsuite2mfe / quickstart.py View on Github external
home_dir = os.path.expanduser('~')
    credential_dir = os.path.join(home_dir, '.credentials')
    if not os.path.exists(credential_dir):
        os.makedirs(credential_dir)
    credential_path = os.path.join(credential_dir,
                                   'admin-reports_v1-python-quickstart.json')

    store = Storage(credential_path)
    credentials = store.get()
    if not credentials or credentials.invalid:
        flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
        flow.user_agent = APPLICATION_NAME
        if flags:
            credentials = tools.run_flow(flow, store, flags)
        else: # Needed only for compatibility with Python 2.6
            credentials = tools.run(flow, store)
        print('Storing credentials to ' + credential_path)
    return credentials
github ultrabug / py3status / py3status / modules / google_calendar.py View on Github external
if not os.path.exists(client_secret_path):
            os.makedirs(client_secret_path)

        flags = tools.argparser.parse_args(args=[])
        store = Storage(self.auth_token)
        credentials = store.get()

        if not credentials or credentials.invalid:
            try:
                flow = client.flow_from_clientsecrets(self.client_secret, SCOPES)
                flow.user_agent = APPLICATION_NAME
                if flags:
                    credentials = tools.run_flow(flow, store, flags)
                else:  # Needed only for compatibility with Python 2.6
                    credentials = tools.run(flow, store)
            except clientsecrets.InvalidClientSecretsError:
                raise Exception("missing client_secret")
            """
            Have to restart i3 after getting credentials to prevent bad output.
            This only has to be done once on the first run of the module.
            """
            self.py3.command_run("{} restart".format(self.py3.get_wm_msg()))

        return credentials
github robert8138 / flask-google-calendar-api-project / Flask_App / src / quickstart.py View on Github external
home_dir = os.path.expanduser('~')
    credential_dir = os.path.join(home_dir, '.credentials')
    if not os.path.exists(credential_dir):
        os.makedirs(credential_dir)
    credential_path = os.path.join(credential_dir,
                                   'calendar-quickstart.json')

    store = oauth2client.file.Storage(credential_path)
    credentials = store.get()
    if not credentials or credentials.invalid:
        flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
        flow.user_agent = APPLICATION_NAME
        if flags:
            credentials = tools.run_flow(flow, store, flags)
        else: # Needed only for compatability with Python 2.6
            credentials = tools.run(flow, store)
        print 'Storing credentials to ' + credential_path
    return credentials
github mozillascience / studyGroup / scripts / updateCalendar.py View on Github external
home_dir = os.path.expanduser('~')
    credential_dir = os.path.join(home_dir, '.credentials')
    if not os.path.exists(credential_dir):
        os.makedirs(credential_dir)
    credential_path = os.path.join(credential_dir,
                                   'google-sfuStudyGroupCalendar.json')

    store = oauth2client.file.Storage(credential_path)
    credentials = store.get()
    if not credentials or credentials.invalid:
        flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
        flow.user_agent = APPLICATION_NAME
        if flags:
            credentials = tools.run_flow(flow, store, flags)
        else:  # Needed only for compatability with Python 2.6
            credentials = tools.run(flow, store)
        print 'Storing credentials to ' + credential_path
    return credentials
github dansanderson / site-publish / tool / publish.py View on Github external
user_config_path = os.path.expanduser(USER_CONFIG_DIR)
    if not os.path.exists(user_config_path):
        os.makedirs(user_config_path)
    credentials_path = os.path.join(user_config_path, CREDENTIALS_FILENAME)

    storage = file.Storage(credentials_path)
    credentials = storage.get()

    if credentials is None or credentials.invalid:
        flow = client.OAuth2WebServerFlow(
            client_id=CLIENT_ID,
            client_secret=CLIENT_SECRET,
            scope='https://www.googleapis.com/auth/userinfo.email')

        credentials = tools.run(flow, storage)

    http = credentials.authorize(httplib2.Http())
    return http
github AppScale / appscale / AppServer / google / storage / speckle / python / api / rdbms_googleapi.py View on Github external
if oauth_storage is None:
      if oauth_credentials_path is None:


        oauth_credentials_path = os.path.expanduser(
            rdbms.OAUTH_CREDENTIALS_PATH)
      oauth_storage = oauth_file.Storage(oauth_credentials_path)
    credentials = oauth_storage.get()
    if credentials is None or credentials.invalid:





      from oauth2client import tools
      credentials = tools.run(GetFlow(), oauth_storage)
    self._transport = credentials.authorize(httplib2.Http())
github googleapis / oauth2client / samples / gtaskqueue_sample / gtaskqueue / taskqueue_cmd_base.py View on Github external
raise app.UsageError('You must specify a project name'
                                 ' using the "--project_name" flag.')
        discovery_uri = (
                FLAGS.api_host + 'discovery/v1/apis/{api}/{apiVersion}/rest')
        try:
            # If the Credentials don't exist or are invalid run through the
            # native client flow. The Storage object will ensure that if
            # successful the good Credentials will get written back to a file.
            # Setting FLAGS.auth_local_webserver to false since we can run our
            # tool on Virtual Machines and we do not want to run the webserver
            # on VMs.
            FLAGS.auth_local_webserver = False
            storage = Storage(FLAGS.credentials_file)
            credentials = storage.get()
            if credentials is None or credentials.invalid == True:
                credentials = run(FLOW, storage)
            http = credentials.authorize(self._dump_request_wrapper(
                    httplib2.Http()))
            api = build('taskqueue',
                       FLAGS.service_version,
                       http=http,
                       discoveryServiceUrl=discovery_uri)
            result = self.run_with_api_and_flags_and_args(api, FLAGS, argv)
            self.print_result(result)
        except HttpError, http_error:
            print 'Error Processing request: %s' % str(http_error)