How to use the oauth2client.client.AccessTokenRefreshError 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 singlerider / lorenzotherobot / oauth2client / appengine.py View on Github external
Since the underlying App Engine app_identity implementation does its own
        caching we can skip all the storage hoops and just to a refresh using the
        API.

        Args:
          http_request: callable, a callable that matches the method signature of
            httplib2.Http.request, used to make the refresh request.

        Raises:
          AccessTokenRefreshError: When the refresh fails.
        """
        try:
            scopes = self.scope.split()
            (token, _) = app_identity.get_access_token(scopes)
        except app_identity.Error, e:
            raise AccessTokenRefreshError(str(e))
        self.access_token = token
github googleads / googleads-dfa-reporting-samples / python / v2.0 / get_creative_field_values.py View on Github external
profileId=profile_id, creativeFieldId=field_id)

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

      for value in response['creativeFieldValues']:
        print ('Found creative field value with ID %s and value "%s".'
               % (value['id'], value['value']))

      if response['creativeFieldValues'] and response['nextPageToken']:
        request = service.creativeFieldValues().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.3 / create_advertiser.py View on Github external
# Construct and save advertiser.
    advertiser = {
        'name': 'Test Advertiser',
        'status': 'APPROVED'
    }

    request = service.advertisers().insert(
        profileId=profile_id, body=advertiser)

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

    print ('Created advertiser with ID %s and name "%s".'
           % (response['id'], response['name']))

  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_6 / insert_offline_mobile_conversion.py View on Github external
request = service.conversions().batchinsert(profileId=profile_id,
                                                body=request_body)
    response = request.execute()

    if not response['hasFailures']:
      print ('Successfully inserted conversion for mobile device ID %s.'
             % mobile_device_id)
    else:
      print ('Error(s) inserting conversion for mobile device ID %s.'
             % mobile_device_id)

      status = response['status'][0]
      for error in status['errors']:
        print '\t[%s]: %s' % (error['code'], error['message'])

  except client.AccessTokenRefreshError:
    print ('The credentials have been revoked or expired, please re-run the '
           'application to re-authorize')
github DataBrewery / cubes / cubes / backends / ga / store.py View on Github external
def get_data(self, **kwargs):
        # Documentation:
        # https://google-api-client-libraries.appspot.com/documentation/analytics/v3/python/latest/analytics_v3.data.ga.html
        ga = self.service.data().ga()

        try:
            response = ga.get(ids='ga:%s' % self.profile_id,
                              **kwargs).execute()
        except TypeError as e:
            raise ArgumentError("Google Analytics Error: %s"
                                % str(e))
        except HttpError as e:
            raise BrowserError("Google Analytics HTTP Error: %s"
                                % str(e))
        except AccessTokenRefreshError as e:
            raise NotImplementedError("Re-authorization not implemented yet")

        return response
github googleads / googleads-dfa-reporting-samples / python / v2.3 / get_content_categories.py View on Github external
request = service.contentCategories().list(profileId=profile_id)

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

      for category in response['contentCategories']:
        print ('Found content category with ID %s and name "%s".'
               % (category['id'], category['name']))

      if response['contentCategories'] and response['nextPageToken']:
        request = service.contentCategories().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 wk8 / Brive / model.py View on Github external
def retrieve_single_document_meta(self, doc_id, is_folder=False):
        try:
            meta = self.drive_service.files().get(fileId=doc_id).execute()
            klass = Folder if is_folder else Document
            return klass(meta, self.folders)
        except AccessTokenRefreshError:
            # most likely 403
            raise client_module.ExpiredTokenException
github googleads / googleads-dfa-reporting-samples / python / v2.1 / get_campaigns.py View on Github external
request = service.campaigns().list(profileId=profile_id)

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

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

      if response['campaigns'] and response['nextPageToken']:
        request = service.campaigns().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 / v3_2 / authenticate_using_user_account.py View on Github external
# Construct a service object via the discovery service.
  service = discovery.build('dfareporting', 'v3.2', http=http)

  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 GoogleChrome / chrome-app-samples / push-guestbook / guestbook-srv / guestbook.py View on Github external
def SendMessages(post_data):
  storage = StorageByKeyName(AdminCredentialsModel,
                             'theadminaccount',
                             'credentials')
  credentials = storage.get()
  if credentials:
    try:
      api_http = credentials.authorize(httplib2.Http())
      for data in post_data:
        api_http.request(
            'https://www.googleapis.com/gcm_for_chrome/v1/messages',
            'POST',
            body=simplejson.dumps(data),
            headers={'Content-Type': 'application/json'})
    except AccessTokenRefreshError:
      logger.warning('Unable to refresh the Push Messaging access token!')