google-trends-api-client
Version:
An fully typed and easy to use client for the google trends api.
38 lines • 1.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getExplorationWidgets = void 0;
const assertValidGoogleTrendsApiTime_1 = require("../assertions/assertValidGoogleTrendsApiTime");
const defineCommonGoogleTrendsApiParametersValue_1 = require("../assertions/defineCommonGoogleTrendsApiParametersValue");
const getFromApiCall_1 = require("./getFromApiCall");
/**
* google returns exploration widgets when you search for keywords, to build their web interface.
*
* for us, it has two uses:
* - enumerating and describing all of the data that can be looked up
* - defining the tokens required to access the data that can be looked up
*
* for example:
* - https://trends.google.com/trends/api/explore?hl=en-US&tz=240&req=%7B%22comparisonItem%22:%5B%7B%22keyword%22:%22mattress+disposal%22,%22geo%22:%22US%22,%22time%22:%22today 12-m%22%7D%5D,%22category%22:0,%22property%22:%22%22%7D&tz=240
*/
const getExplorationWidgets = async ({ keywords, geo, time, category, property, hl, tz, }, agentOptions = {}) => {
const response = await (0, getFromApiCall_1.getFromApiCall)({
path: 'trends/api/explore',
agentOptions,
queryParams: {
...(0, defineCommonGoogleTrendsApiParametersValue_1.defineCommonGoogleTrendsApiParametersValue)({ hl, tz }),
req: JSON.stringify({
comparisonItem: keywords.map((keyword) => ({
keyword,
geo: geo ?? 'US',
time: (0, assertValidGoogleTrendsApiTime_1.assertValidGoogleTrendsApiTime)(time ?? 'today 12-m'),
})),
category: category ?? 0,
property: property ?? '',
}),
},
});
const result = JSON.parse(response);
return result;
};
exports.getExplorationWidgets = getExplorationWidgets;
//# sourceMappingURL=getExplorationWidgets.js.map