How to use the oauth2client.client 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 NYPL-Simplified / circulation / tests / admin / test_google_oauth_admin_authentication_provider.py View on Github external
def step2_exchange(self, auth_code):
                raise GoogleClient.FlowExchangeError("mock error")
        self.google.dummy_client = ExceptionRaisingClient()
github tokland / shoogle / shoogle / auth / auth.py View on Github external
def _get_credentials_interactively(flow, storage, get_code_callback):
    """Return the credentials asking the user."""
    flow.redirect_uri = oauth2client.client.OOB_CALLBACK_URN
    authorize_url = flow.step1_get_authorize_url()
    code = get_code_callback(authorize_url)
    if code:
        credential = flow.step2_exchange(code, http=None)
        storage.put(credential)
        credential.set_store(storage)
        return credential
github googleads / googleads-adxseller-examples / python / v1.1 / get_all_ad_units.py View on Github external
try:
    # Retrieve ad unit list in pages and display data as we receive it.
    request = service.adunits().list(adClientId=ad_client_id,
        maxResults=MAX_PAGE_SIZE)

    while request is not None:
      result = request.execute()
      ad_units = result['items']
      for ad_unit in ad_units:
        print ('Ad unit with code "%s", name "%s" and status "%s" was found. ' %
               (ad_unit['code'], ad_unit['name'], ad_unit['status']))

      request = service.adunits().list_next(request, result)

  except client.AccessTokenRefreshError:
    print ('The credentials have been revoked or expired, please re-run the '
           'application to re-authorize')
github googleads / googleads-dfa-reporting-samples / python / v2.0 / authenticate_using_service_account.py View on Github external
# Construct a service object via the discovery service.
  service = discovery.build('dfareporting', 'v2.0', http=http_auth)

  try:
    # Construct the request.
    request = service.userProfiles().list()

    # Execute request and print response.
    response = request.execute()

    for profile in response['items']:
      print ('Found user profile with ID %s and user name "%s".'
             % (profile['profileId'], profile['userName']))

  except client.AccessTokenRefreshError:
    print ('The credentials have been revoked or expired, please re-run the '
           'application to re-authorize')
github googleads / googleads-dfa-reporting-samples / python / v2.1 / get_placements.py View on Github external
while True:
      # Execute request and print response.
      response = request.execute()

      for placement in response['placements']:
        print ('Found placement with ID %s and name "%s" for campaign "%s".'
               % (placement['id'], placement['name'],
                  placement['campaignId']))

      if response['placements'] and response['nextPageToken']:
        request = service.placements().list_next(request, response)
      else:
        break

  except client.AccessTokenRefreshError:
    print ('The credentials have been revoked or expired, please re-run the '
           'application to re-authorize')
github googleads / googleads-dfa-reporting-samples / python / v2_7 / assign_advertiser_to_advertiser_group.py View on Github external
try:
    # Construct the request.
    advertiser = {
        'advertiserGroupId': advertiser_group_id
    }

    request = service.advertisers().patch(
        profileId=profile_id, id=advertiser_id, body=advertiser)

    # Execute request and print response.
    response = request.execute()

    print ('Assigned advertiser with ID %s to advertiser group with ID %s.'
           % (response['id'], response['advertiserGroupId']))

  except client.AccessTokenRefreshError:
    print ('The credentials have been revoked or expired, please re-run the '
           'application to re-authorize')
github Yeraze / CalendarHangout / hangoutFix.py View on Github external
return thecount as text
                                end tell
                            end run''' % (uid, event['hangoutLink']))
                        tstart = time.time()
                        processed = aScript.run()
                        tend = time.time()
                        print("  Processed %s items in %i seconds" % (processed, tend-tstart))
                    else:
                        print("  Skipping, already captured")
                else:
                    print ("  Skipping, declined")
            else:
                print ("how it is possible")


    except client.AccessTokenRefreshError:
        print ("The credentials have been revoked or expired, please re-run"
               "the application to re-authorize")
github google / turbinia / tools / plaso_pubsub.py View on Github external
def CreateServiceClient(service):
  """Creates an API client for talking to Google Cloud.

  Args:
      service: String of service name.
  Returns:
      A client object for interacting with the cloud service.
  """
  WriteToStdOut(u'Create API client for service: {0:s}'.format(service))
  credentials = oauth2client.GoogleCredentials.get_application_default()
  http = httplib2.Http()
  credentials.authorize(http)
  return discovery.build(service, 'v1', http=http)
github cfbao / google-drive-trash-cleaner / cleaner.py View on Github external
def get_credentials(flags):
    """Gets valid user credentials from storage.

    If nothing has been stored, or if the stored credentials are invalid,
    the OAuth2 flow is completed to obtain the new credentials.

    Returns:
        Credentials, the obtained credential.
    """
    store = Storage(flags.credfile)
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        credentials = store.get()
    if not credentials or credentials.invalid:
        flow = client.OAuth2WebServerFlow(**CLIENT_CREDENTIAL)
        credentials = tools.run_flow(flow, store, flags)
        print('credential file saved at\n\t' + flags.credfile)
    return credentials
github googleads / googleads-dfa-reporting-samples / python / v2.3 / get_user_roles.py View on Github external
request = service.userRoles().list(profileId=profile_id, fields=fields)

    while True:
      # Execute request and print response.
      response = request.execute()

      for user_role in response['userRoles']:
        print ('Found user role with ID %s and name "%s".'
               % (user_role['id'], user_role['name']))

      if response['userRoles'] and response['nextPageToken']:
        request = service.userRoles().list_next(request, response)
      else:
        break

  except client.AccessTokenRefreshError:
    print ('The credentials have been revoked or expired, please re-run the '
           'application to re-authorize')