def makecall(self):
# self.service is causing recursion error when left as class attribute #swap service to mock
argv = []
service, flags = sample_tools.init(
argv, 'webmasters', 'v3', __doc__, __file__, parents=[],
scope='https://www.googleapis.com/auth/webmasters.readonly')
try:
if not self.clientquery['property_uri']:
raise SystemExit('Unable to locate client URI for %s. Exiting.' % (self.clientquery['property_uri']))
else:
# response = self.service.searchanalytics().query(siteUrl=self.clientquery['property_uri'], body=self.request).execute() #swap response to mock
response = service.searchanalytics().query(siteUrl=self.clientquery['property_uri'], body=self.request).execute() #swap response to mock
return response
except TypeError as error:
raise SystemExit('There was an error in constructing the query : %s' % (error))
except HttpError as error:
# Handle API errors
print('There was an API error : %s : %s' % (error.resp.status, error._get_reason()))
response = [self.clientquery['query_date'],
self.clientquery['clientName'],
self.clientquery['siteMode'],
int(0),
'FALSE',
error.resp.status,
error._get_reason()]
return response
except AccessTokenRefreshError:
raise SystemExit('The credentials have been revoked or expired, please re-run the application to re-authorize')
except Exception as e:
raise SystemExit(e)
评论列表
文章目录