Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def step2_exchange(self, auth_code):
raise GoogleClient.FlowExchangeError("mock error")
self.google.dummy_client = ExceptionRaisingClient()
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
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')
# 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')
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')
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')
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")
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)
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
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')