google trends不像google ads一样公开了api文档。我们要想使用google trends的api就需要手动去分析google trends的规范。
为了方便后来人,这里直接贴出获取api token的接口。
https://trends.google.com/trends/api/explore
查询参数(除了req里面的内容,其他都是固定的):
hl: zh-CN
tz: -480
req: {"comparisonItem":[{"keyword":"mac","geo":"US","time":"today 12-m"}],"category":0,"property":""}
tz: -480
所以整个url为:
https://trends.google.com/trends/api/explore?hl=zh-CN&tz=-480&req={"comparisonItem":[{"keyword":"mac","geo":"US","time":"today 12-m"}],"category":0,"property":""}&tz=-480
重点来了,这样请求下来的数据会在正常的json前面加上4个符号。。例如:
)
]
}'
{
"widgets": [
{
"request": {}
}]
}
所以正常使用的时候,需要截取掉前面无效的部分才是正常的json。token包含在json数据中。