【发布时间】:2018-02-26 23:13:42
【问题描述】:
我已获得使用专用 Google Extended Trends API for Health 进行研究的许可。 我想训练自己使用该工具,所以首先在 Google 提供的 Google Extended Trends API for Health-Getting Started Guide.pdf 文件中实现示例 python 代码。 在我看来,这段代码应该可以工作。如果我得到它的工作,我可以开始修改它来创建我自己的请求。如果我让它工作......
我正在使用 Python 3.6.3
我在这里看到了类似的帖子: Google Extended Trends API for Health in python 但他们没有得到答案。
这是我在运行代码时得到的完整回溯:
Traceback(最近一次通话最后一次):
文件“C:\Google 趋势\Google Trends_Health API\Google 趋势示例代码.py”,第 156 行,在 main() 中
文件“C:\Google 趋势\Google Trends_Health API\Google 趋势示例代码.py”,第 142 行,主频 = 'day')
GetQueryVolumes res = req.execute () 中的文件“C:\Google 趋势\Google Trends_Health API\Google 趋势示例代码.py”,第 104 行
文件“C:\Program Files\Python36\lib\site-packages\oauth2client_helpers.py”,第 133 行,在 positional_wrapper 中 返回包装(*args,**kwargs)
文件“C:\Program Files\Python36\lib\site-packages\googleapiclient\http.py”,第 839 行,正在执行中
引发 HttpError(resp, content, uri=self.uri) googleapiclient.errors.HttpError:https://www.googleapis.com/trends/v1beta/timelinesForHealth?terms=flu&terms=cough&time.startDate=2011-01-01&time.endDate=2015-01-01&timelineResolution=day&geoRestriction.region=US- MA&key={是的,就像我在这里展示的那样!}&alt=json 返回“错误请求”>
我在回溯中看到它正在从 OAuth 文件夹调用 helpers.py 模块,所以想知道这一点:400 (Bad Request) when requesting GA API 但指南说:“注意:此 API 不需要 OAuth2。”
我还可以在仪表板上看到请求正在注册,因此它一定与 JSON 请求的实际格式有关。我不是 JSON 专家,所以我可能需要帮助。 从上面提取的请求是: https://www.googleapis.com/trends/v1beta/timelinesForHealth?terms=flu&terms=cough&time.startDate=2011-01-01&time.endDate=2015-01-01&timelineResolution=day&geoRestriction.region=US-MA&key=APIKEY&alt=json
关于出了什么问题的任何线索?我尝试从 v1beta 更改 API 版本,这给了我一个错误版本名称的特定错误,所以不是版本名称有问题。 我似乎找不到任何明确的答案。
谢谢
【问题讨论】:
标签: python json google-api