Origin of tokens in Google trends API call

倾然丶 夕夏残阳落幕 提交于 2019-12-21 02:47:31

问题


When I download a CSV from a Google trends query (e.g. here), I see a HTTP GET request to

https://www.google.com/trends/api/widgetdata/multiline/csv

with params

req:{"time":"2012-02-18 2017-02-18","resolution":"WEEK","locale":"en-GB","comparisonItem":[{"geo":{},"complexKeywordsRestriction":{"keyword":[{"type":"BROAD","value":"trump"}]}}],"requestOptions":{"property":"","backend":"IZG","category":0}}
token:APP6_UEAAAAAWKm9N57FxjXrnfxhxhe5SEax6DyR97sY
tz:-120

The req and tz params make sense, but I am unsure how the token is generated. Can someone explain to me where this comes from? Do I need to use oauth2 packages to create these tokens?


回答1:


This token is generated for result widgets, each widget will have its own token.

Where is this token come from?

When page https://trends.google.com/trends/explore?q=trump is opened, an Ajax GET request is sent to https://trends.google.com/trends/api/explore, with query parameters:

In the response of this Ajax request, there is a widgets field which contains all result widget data. Each widget will have a unique token:

When Download CSV operation is triggered (on specific widget, GET request to https://trends.google.com/trends/api/widgetdata/multiline/csv), the token information of that widget is extracted and delivered as query parameter:

Please note the token in the response and the token in the download csv request is identical (for the same widget).

How is the token generated?

Theoretically, all random and unique string can be used as token to protect widget. Google may have its own algorithm.



来源:https://stackoverflow.com/questions/42317489/origin-of-tokens-in-google-trends-api-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!