pat310 / google-trends-api

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

JSON Parse error in one of your examples #50

Closed Howon closed 7 years ago

Howon commented 7 years ago

When I run

googleTrends.interestOverTime({keyword: 'Women\'s march'})
.then(function(results){
  console.log('These results are awesome', results);
})
.catch(function(err){
  console.error('Oh no there was an error', err);
});

This happens.

Oh no there was an error SyntaxError: Unexpected token L in JSON at position 0
    at JSON.parse (<anonymous>)
    at /Users/howonbyun/Desktop/work/adi/is-it-fire/node_modules/google-trends-api/lib/google-trends-api.min.js:146:22
    at process._tickCallback (internal/process/next_tick.js:103:7)

The endpoint is probably wrong or something. Has anyone used this successfully?

CosmicWebServices commented 7 years ago

I just got this error also

turnerniles commented 7 years ago

I think it's happening for all requests. I logged the request it makes and response it gets.

Request: { host: 'www.google.com', method: 'GET', path: '/trends/api/explore?hl=en-US&req=%7B%22comparisonItem%22%3A%5B%7B%22keyword%22%3A%22Women\'s%20march%22%2C%22hl%22%3A%22en-US%22%2C%22endTime%22%3A%222017-02-20T05%3A59%3A05.033Z%22%2C%22startTime%22%3A%222004-01-01T00%3A00%3A00.000Z%22%2C%22time%22%3A%222004-01-1%202017-02-20%22%7D%5D%2C%22cat%22%3A0%7D&tz=300' }

Response:

<HTML><HEAD><meta` http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://trends.google.com/trends/api/explore?hl=en-US&amp;req=%7B%22comparisonItem%22%3A%5B%7B%22keyword%22%3A%22Women&#39;s%20march%22%2C%22hl%22%3A%22en-US%22%2C%22endTime%22%3A%222017-02-20T05%3A59%3A05.033Z%22%2C%22startTime%22%3A%222004-01-01T00%3A00%3A00.000Z%22%2C%22time%22%3A%222004-01-1%202017-02-20%22%7D%5D%2C%22cat%22%3A0%7D&amp;tz=300">here</A>.
</BODY></HTML>

Weird because if you GET: www.google.com/trends/api/explore?hl=en-US&req=%7B%22comparisonItem%22%3A%5B%7B%22keyword%22%3A%22Women\'s%20march%22%2C%22hl%22%3A%22en-US%22%2C%22endTime%22%3A%222017-02-20T05%3A59%3A05.033Z%22%2C%22startTime%22%3A%222004-01-01T00%3A00%3A00.000Z%22%2C%22time%22%3A%222004-01-1%202017-02-20%22%7D%5D%2C%22cat%22%3A0%7D&tz=300 in Postman it returns the JSON.

Howon commented 7 years ago

Right. I was wondering about the same thing

pat310 commented 7 years ago

@Howon @CosmicWebServices @turnerniles looks like the url changed, hopefully this PR #51 fixes it