pat310 / google-trends-api

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

Is there anyway to have a date parameter for trendData() ? #28

Closed ghost closed 8 years ago

ghost commented 8 years ago

In order to see trend data for a keyword in a given time frame e.g. past year, past month, past week.

I noticed it wasn't in the documentation, also didn't work when I tested it.

pat310 commented 8 years ago

@SuttJ Not at this point, but I'm hoping to add this functionality soon. I'll let you know when I do!

ghost commented 8 years ago

Thanks! - I was gonna poke around and see if I could do it this weekend.

pat310 commented 8 years ago

Awesome, I was thinking I would need to modify the url in src/utils/trendData to add some date parameters. Right now the url that it retrieves trend data from is: http://www.google.com/trends/fetchComponent?q="${keyword}"&cid=TIMESERIES_GRAPH_0&export=3

But there must be a way to specify date

ghost commented 8 years ago

So I played with the url request a bit and I've discovered that date specifications are done by adding &date=foo to the url. So in this case it would look like: http://www.google.com/trends/fetchComponent q="${keyword}"&cid=TIMESERIES_GRAPH_0&export=3&date=foo

For the date options: Past 30 days: date=today%201-m Past 7 days: date=now%207-d Past 24 Hours: date=now%201-d

If you wanna see all options, just go to https://www.google.com/trends/explore?date=now%201-H&q=Apple and change the date dropdown menu and look at how the date value in the url changes.

ghost commented 8 years ago

So I tried just adding one of the date statements to the url in src/utilities/trendData but it makes the parseJSON() function in src/resources/htmlParser.js throw an error.

pat310 commented 8 years ago

Hmm, I'm hoping I will have a chance this weekend to take a look. Sorry for the delay!

pat310 commented 8 years ago

@SuttJ Added a timePeriod parameter to trendData - for example:

{keywords: ['michael phelps'], timePeriod: {type: 'hour', value: 5}}