【发布时间】:2021-06-30 14:20:04
【问题描述】:
最近我一直在使用 Google Cloud API 进行一些数据分析项目。目前,我一直遵循其他网站的说明,并以此为基础制作自己的数据集。但是,我一直在使用 Google Cloud API 时遇到错误。
例如,我正在尝试以下文章中的方法:https://practicaldatascience.co.uk/data-science/how-to-query-the-google-search-console-api-with-ecommercetools
然而,Python 的响应如下:
错误:服务帐户信息不是预期的格式,缺少字段 token_uri、client_email。
我在文章中提到的“OAuth 2.0 客户端 ID”下创建了基本凭据。
这是我目前拥有的代码:
import pandas as pd
from ecommercetools import seo
from oauth2client.service_account import ServiceAccountCredentials
pd.set_option('max_colwidth', 100)
key = "G:\Python Projects\query_gsc_secrets.json"
site_url = "https://startselect.com/"
start_date = "2019-01-01"
end_date = "2020-12-31"
print(key)
payload = {
'startDate': start_date,
'endDate': end_date,
'dimensions': ["page"],
'rowLimit': 10000,
'startRow': 0
}
df = seo.query_google_search_console(key, site_url, payload)
df.sort_values(by='clicks', ascending=False).head()
我问这个的原因是因为这个错误似乎以一种或另一种形式重复出现。创建凭据时我是否遗漏了什么?代码有错误吗?
提前致谢!
【问题讨论】:
标签: python api google-cloud-platform google-cloud-functions