pat310 / google-trends-api

An API layer on top of google trends
https://www.npmjs.com/package/google-trends-api
MIT License
874 stars 174 forks source link

Doing a basic function with startTime and getting the value from 3 days ago. #153

Open ethanolle opened 3 years ago

ethanolle commented 3 years ago

Hello I'm doing a basic function with the google-trends-api and I'm getting the last value from 3 days ago. For example: const googleTrends = require("google-trends-api");

const getData = (stockName) => { let week = 604800000; googleTrends.interestOverTime( { keyword: "Valentines Day", startTime: new Date(Date.now() - week), }, function (err, results) { if (err) console.log("oh no error!", err); else console.log(results + Date.now()); } ); };

getData("btc");

exports.getData = getData; ` And I also can't get the value from the last day. and the last value that I get is "formattedTime":"Feb 9, 2021","formattedAxisTime":"Feb 9","value":[100],"hasData":[true]," and today is the the 12 of February and I'm getting the value from the 9. hope for help thanks pat310 for this amazing npm

gentlemanjohn commented 3 years ago

I too am having this issue. I noticed that the Google Trends site also lops off the last two days unless the time frame is 7 days or less, but I can't get yesterday or today's data no matter what I put into startTime.

        const end = moment().toDate();

        const start = moment().subtract(6, 'days').toDate();

        const options = {
            keyword: 'blah',
            property: 'web',
            startTime: start,
            // endTime: end
        }

        const result = JSON.parse(await googleTrends.interestOverTime(options));
gentlemanjohn commented 3 years ago

I'm able to get recent data if I change startTime to 6 days ago or less and granularTimeResolution: true

ethanolle commented 3 years ago

I just understood that's the probleme is not the NPM but google trends that's not giving any value of the last days with more than 1 week