我正在尝试查询我网站的搜索分析数据 . 我确信这是我创建的网站 . 但当我尝试使用google-api-python-client请求时,我收到403错误:
x = gapi.webmasters_service.searchanalytics().query(body={"startDate": "2014-01-01", "endDate": "2014-01-01"}, siteUrl="http://seozeo.com.tr").execute()
输出是:
HttpError:https://www.googleapis.com/webmasters/v3/sites/http%3A%2F%2Fseozeo.com.tr/searchAnalytics/query?alt=json返回“用户没有足够的网站权限”http ://seozeo.com.tr/' . 另请参阅:https://support.google.com/webmasters/answer/2451999 . “>
这是gapi类:
class GoogleApi(object):
_instance = None
def __init__(self):
self.credentials = self._getCredentials()
http = self.credentials.authorize(httplib2.Http())
self.webmasters_service = build('webmasters', 'v3', http=http)
self.analytics_service = build('analytics', 'v3', http=http)
def _getCredentials(self):
storage = Storage("credentials_storage")
credentials = storage.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(
'client_secrets.json',
scope='https://www.googleapis.com/auth/webmasters.readonly',
redirect_uri='urn:ietf:wg:oauth:2.0:oob')
auth_uri = flow.step1_get_authorize_url()
webbrowser.open(auth_uri)
auth_code = raw_input('Enter the auth code: ')
credentials = flow.step2_exchange(auth_code)
storage.put(credentials)
return credentials