google-trends-api icon indicating copy to clipboard operation
google-trends-api copied to clipboard

interestOverTime throws error "unexpected json" for example code also

Open surya-kiran27 opened this issue 4 years ago • 3 comments

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

surya-kiran27 avatar Feb 22 '21 12:02 surya-kiran27

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

grmmph avatar Feb 28 '21 09:02 grmmph

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

jelisejev avatar Mar 09 '21 10:03 jelisejev

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???

sergiubalauca avatar Mar 22 '21 17:03 sergiubalauca