I am using google trends API to eventually export trends data to an excel file. The issue is I want to extract ONLY the formattedTime and value for my keywords.
JS not a strong suit of mine. How do I pull only these parameters? Or is there a way I can assign these parameters to key value dictionary pair?
Thank you.
json output
{
"default": {
"timelineData":[
{
"time":"1511629200",
"formattedTime":"Nov 25, 2017 at 12:00 PM",
"formattedAxisTime":"Nov 25 at 12:00 PM",
"value":[44],
"formattedValue":["44"]
},
{
"time":"1511632800",
"formattedTime":"Nov 25, 2017 at 1:00 PM",
"formattedAxisTime":"Nov 25 at 1:00 PM",
"value":[41],
"formattedValue":["41"]
}
]
}
}
code
'use strict';
const googleTrends = require('google-trends-api');
var animals = ['hamsters', 'puppies'];
for (var key in animals) {
console.log(animals[key]);
googleTrends.interestOverTime({
keyword: key,
startTime: new Date(Date.now() - (167.9 * 60 * 60 * 1000)),
granularTimeResolution: true,
}, function(err, results) {
if (err)
console.log('oh no error!', err);
else
console.log(results);
console.log("--------------------------")
});
}