pat310 / google-trends-api

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

interestOverTime throws error "unexpected json" for example code also #154

Open surya-kiran27 opened 3 years ago

surya-kiran27 commented 3 years ago

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); });

grmmph commented 3 years ago

Did you get any ideas? I think it happens from some ips, as google block some of the ips

jelisejev commented 3 years ago

I'm getting this error on an application hosted on AWS. Looks like indeed google is blocking the IP. This is the error that is generated:


'</BODY></HTML>\r '
--
'<A HREF="https://www.google.com/sorry/index?continue=https://trends.google.com/trends/api/explore%3Fhl%3Den-US%26req%3D%257B%2522comparisonItem%2522%253A%255B%257B%2522keyword%2522%253A%2522Samsung%2520Galaxy%2520A31%2520A315%2520Dual%2520Sim%25204GB%2520RAM%2520128GB%2520Black%2522%252C%2522geo%2522%253A%2522ES%2522%252C%2522startTime%2522%253A%25222020-03-09T10%253A31%253A35.322Z%2522%252C%2522hl%2522%253A%2522en-US%2522%252C%2522category%2522%253A0%252C%2522timezone%2522%253A0%252C%2522property%2522%253A%2522%2522%252C%2522endTime%2522%253A%25222021-03-09T10%253A31%253A35.322Z%2522%252C%2522time%2522%253A%25222020-03-9%25202021-03-9%2522%257D%252C%257B%2522keyword%2522%253A%2522Samsung%2520Galaxy%2520A31%2520A315%2520Dual%2520Sim%25204GB%2520RAM%2520128GB%2520Black%2522%252C%2522geo%2522%253A%2522IT%2522%252C%2522startTime%2522%253A%25222020-03-09T10%253A31%253A35.322Z%2522%252C%2522hl%2522%253A%2522en-US%2522%252C%2522category%2522%253A0%252C%2522timezone%2522%253A0%252C%2522property%2522%253A%2522%2522%252C%2522endTime%2522%253A%25222021-03-09T10%253A31%253A35.322Z%2522%252C%2522time%2522%253A%25222020-03-9%25202021-03-9%2522%257D%252C%257B%2522keyword%2522%253A%2522Samsung%2520Galaxy%2520A31%2520A315%2520Dual%2520Sim%25204GB%2520RAM%2520128GB%2520Black%2522%252C%2522geo%2522%253A%2522DE%2522%252C%2522startTime%2522%253A%25222020-03-09T10%253A31%253A35.322Z%2522%252C%2522hl%2522%253A%2522en-US%2522%252C%2522category%2522%253A0%252C%2522timezone%2522%253A0%252C%2522property%2522%253A%2522%2522%252C%2522endTime%2522%253A%25222021-03-09T10%253A31%253A35.322Z%2522%252C%2522time%2522%253A%25222020-03-9%25202021-03-9%2522%257D%252C%257B%2522keyword%2522%253A%2522Samsung%2520Galaxy%2520A31%2520A315%2520Dual%2520Sim%25204GB%2520RAM%2520128GB%2520Black%2522%252C%2522geo%2522%253A%2522FR%2522%252C%2522startTime%2522%253A%25222020-03-09T10%253A31%253A35.322Z%2522%252C%2522hl%2522%253A%2522en-US%2522%252C%2522category%2522%253A0%252C%2522timezone%2522%253A0%252C%2522property%2522%253A%2522%2522%252C%2522endTime%2522%253A%25222021-03-09T10%253A31%253A35.322Z%2522%252C%2522time%2522%253A%25222020-03-9%25202021-03-9%2522%257D%255D%252C%2522category%2522%253A0%252C%2522property%2522%253A%2522%2522%257D%26tz%3D0&amp;hl=en-US&amp;q=EgQNMYZsGIednYIGIhkA8aeDS4uOroYxPr5sx7kbKG-Lcswwpez9MgFy">here</A>.\r ' +
'The document has moved ' +
'<H1>302 Moved</H1> ' +
'<TITLE>302 Moved</TITLE></HEAD><BODY> ' +
requestBody: '<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> ' +
at async Server.renderToHTMLWithComponents (/app/node_modules/next/dist/next-server/server/next-server.js:132:387) {
at async /app/node_modules/next/dist/next-server/server/next-server.js:100:142
at async /app/node_modules/next/dist/next-server/server/next-server.js:107:97
at async renderToHTML (/app/node_modules/next/dist/next-server/server/render.js:40:215)
at async getServerSideProps (/app/.next/server/pages/search.js:396:20)
at async Promise.all (index 0)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at /app/node_modules/google-trends-api/lib/google-trends-api.min.js:1:5731
at d (/app/node_modules/google-trends-api/lib/google-trends-api.min.js:1:4531)
at JSON.parse (<anonymous>)
SyntaxError: Unexpected token L in JSON at position 0
sergiubalauca commented 3 years ago

Hi, I am getting the same html response from google, as they think they detect unusual traffic. My api is hosted on heroku and at times, the client calls seem to work perfectly fine, but mostly, in 95% of the cases it fails. Locally, I have no issues calling the google-trends api numerous times. It seems like a hosting issue, not being on the same domain. Any progress on bypassing this issue???