问题
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