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

Is this API still working? #130

Open Astraport opened 4 years ago

Astraport commented 4 years ago

When I try to make a request:

var googleTrends = require('google-trends-api');

googleTrends.relatedQueries({keyword: 'keywords', startTime: '201811', endTime: '201812', geo: 'US'})
.then(function(results){
    console.log("Here are your google trend results!", results);
})
.catch(function(err){
    console.log("there was an error :(", err);
});

I always get errors - The requested URL was not found on this server.: ` [Symbol(kBytesWritten)]: 232,

},
connection: TLSSocket {
  _tlsOptions: [Object],
  _secureEstablished: true,
  _securePending: false,
  _newSessionPending: false,
  _controlReleased: true,
  _SNICallback: null,
  servername: 'trends.google.com',
  alpnProtocol: false,
  authorized: true,
  authorizationError: null,
  encrypted: true,
  _events: [Object: null prototype],
  _eventsCount: 11,
  connecting: false,
  _hadError: false,
  _parent: null,
  _host: 'trends.google.com',
  _readableState: [ReadableState],
  readable: false,
  _maxListeners: undefined,
  _writableState: [WritableState],
  writable: false,
  allowHalfOpen: false,
  _sockname: null,
  _pendingData: null,
  _pendingEncoding: '',
  server: undefined,
  _server: null,
  ssl: null,
  _requestCert: true,
  _rejectUnauthorized: true,
  parser: null,
  _httpMessage: [ClientRequest],
  write: [Function: writeAfterFIN],
  [Symbol(res)]: [TLSWrap],
  [Symbol(asyncId)]: 23,
  [Symbol(kHandle)]: null,
  [Symbol(lastWriteQueueSize)]: 0,
  [Symbol(timeout)]: null,
  [Symbol(kBuffer)]: null,
  [Symbol(kBufferCb)]: null,
  [Symbol(kBufferGen)]: null,
  [Symbol(kBytesRead)]: 2719,
  [Symbol(kBytesWritten)]: 232,
  [Symbol(connect-options)]: [Object]
},
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: true,
headers: {
  'cache-control': 'no-cache, no-store, max-age=0, must-revalidate',
  pragma: 'no-cache',
  expires: 'Mon, 01 Jan 1990 00:00:00 GMT',
  date: 'Sun, 01 Dec 2019 10:39:41 GMT',
  'content-type': 'text/html; charset=utf-8',
  p3p: 'CP="This is not a P3P policy! See g.co/p3phelp for more info."',
  'content-security-policy': "script-src 'report-sample' 'nonce-IfqyQwm/yLcc

312ovP0+kQ' 'unsafe-inline' 'strict-dynamic' https: http: 'unsafe-eval';object-s rc 'none';base-uri 'self';report-uri /cspreport", 'x-content-type-options': 'nosniff', 'x-xss-protection': '1; mode=block', server: 'GSE', 'set-cookie': [Array], 'alt-svc': 'quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000, h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000 ,h3-Q043=":443"; ma=2592000', 'accept-ranges': 'none', vary: 'Accept-Encoding', connection: 'close' }, rawHeaders: [ 'Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate', 'Pragma', 'no-cache', 'Expires', 'Mon, 01 Jan 1990 00:00:00 GMT', 'Date', 'Sun, 01 Dec 2019 10:39:41 GMT', 'Content-Type', 'text/html; charset=utf-8', 'P3P', 'CP="This is not a P3P policy! See g.co/p3phelp for more info."', 'Content-Security-Policy', "script-src 'report-sample' 'nonce-IfqyQwm/yLcc312ovP0+kQ' 'unsafe-inline' 'strict-dynamic' https: http: 'unsafe-eval';object-src 'none';base-uri 'self';r eport-uri /cspreport", 'X-Content-Type-Options', 'nosniff', 'X-XSS-Protection', '1; mode=block', 'Server', 'GSE', 'Set-Cookie', 'NID=192=3mhrvIYOQzsBq8fxwEglUqspia0ptWAai6y4Qbb5pAcKEJSUtYP7ozqlpGjozMZj LIf5O1QTBER1DANhmY-KHKtGaTZVKSTehwnQ8dmyjfuqAYs6N33yzL_nwhy3Tk9gPogE9GLYePj4FKt SgsuNHTGIjl7tVNkKULtcVa0_4; expires=Mon, 01-Jun-2020 10:39:41 GMT; path=/; domai n=.google.com; HttpOnly', 'Alt-Svc', 'quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":4 43"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=": 443"; ma=2592000', 'Accept-Ranges', 'none', 'Vary', 'Accept-Encoding', 'Connection', 'close' ], trailers: {}, rawTrailers: [], aborted: false, upgrade: false, url: '', method: null, statusCode: 404, statusMessage: 'Not Found', client: TLSSocket { _tlsOptions: [Object], _secureEstablished: true, _securePending: false, _newSessionPending: false, _controlReleased: true, _SNICallback: null, servername: 'trends.google.com', alpnProtocol: false, authorized: true, authorizationError: null, encrypted: true, _events: [Object: null prototype], _eventsCount: 11, connecting: false, _hadError: false, _parent: null, _host: 'trends.google.com', _readableState: [ReadableState], readable: false, _maxListeners: undefined, _writableState: [WritableState], writable: false, allowHalfOpen: false, _sockname: null, _pendingData: null, _pendingEncoding: '', server: undefined, _server: null, ssl: null, _requestCert: true, _rejectUnauthorized: true, parser: null, _httpMessage: [ClientRequest], write: [Function: writeAfterFIN],

  [Symbol(asyncId)]: 23,
  [Symbol(kHandle)]: null,
  [Symbol(lastWriteQueueSize)]: 0,
  [Symbol(timeout)]: null,
  [Symbol(kBuffer)]: null,
  [Symbol(kBufferCb)]: null,
  [Symbol(kBufferGen)]: null,
  [Symbol(kBytesRead)]: 2719,
  [Symbol(kBytesWritten)]: 232,
  [Symbol(connect-options)]: [Object]
},
_consuming: true,
_dumped: false,
req: ClientRequest {
  _events: [Object: null prototype],
  _eventsCount: 5,
  _maxListeners: undefined,
  outputData: [],
  outputSize: 0,
  writable: true,
  _last: true,
  chunkedEncoding: false,
  shouldKeepAlive: false,
  useChunkedEncodingByDefault: false,
  sendDate: false,
  _removedConnection: false,
  _removedContLen: false,
  _removedTE: false,
  _contentLength: 0,
  _hasBody: true,
  _trailer: '',
  finished: true,
  _headerSent: true,
  socket: [TLSSocket],
  connection: [TLSSocket],
  _header: 'GET /trends/fetchComponent?q=OJ%20Simpson&cid=TIMESERIES_GRAPH_0

&export=3 HTTP/1.1\r\n' + 'referer: http://www.google.com/trends/fetchComponent?q=OJ%20Simpson&cid =TIMESERIES_GRAPH_0&export=3&\r\n' + 'host: trends.google.com\r\n' + 'Connection: close\r\n' + '\r\n', _onPendingData: [Function: noopPendingOutput], agent: [Agent], socketPath: undefined, method: 'GET', path: '/trends/fetchComponent?q=OJ%20Simpson&cid=TIMESERIES_GRAPH_0&export =3', _ended: true, res: [Circular], aborted: false, timeoutCb: null, upgradeOrConnect: false, parser: null, maxHeadersCount: null,

  [Symbol(isCorked)]: false,
  [Symbol(kOutHeaders)]: [Object: null prototype]
},
request: Request {
  _events: [Object: null prototype],
  _eventsCount: 5,
  _maxListeners: undefined,
  uri: [Url],
  readable: true,
  writable: true,
  _qs: [Querystring],
  _auth: [Auth],
  _oauth: [OAuth],
  _multipart: [Multipart],
  _redirect: [Redirect],
  _tunnel: [Tunnel],
  _rp_resolve: [Function],
  _rp_reject: [Function],
  _rp_promise: [Promise [Object]],
  _rp_callbackOrig: undefined,
  callback: [Function],
  _rp_options: [Object],
  headers: [Object],
  setHeader: [Function],
  hasHeader: [Function],
  getHeader: [Function],
  removeHeader: [Function],
  method: 'GET',
  localAddress: undefined,
  pool: {},
  dests: [],
  __isRequestRequest: true,
  _callback: [Function: RP$callback],
  proxy: null,
  tunnel: true,
  setHost: true,
  originalCookieHeader: undefined,
  _disableCookies: true,
  _jar: undefined,
  port: 443,
  host: 'trends.google.com',
  path: '/trends/fetchComponent?q=OJ%20Simpson&cid=TIMESERIES_GRAPH_0&export

=3', httpModule: [Object], agentClass: [Function: Agent], href: 'https://trends.google.com/trends/fetchComponent?q=OJ%20Simpson&cid= TIMESERIES_GRAPH_0&export=3', ntick: true, response: [Circular], originalHost: 'trends.google.com', originalHostHeaderName: 'host', agent: [Agent], _started: true, req: [ClientRequest], responseContent: [Circular], _destdata: true, _ended: true, _callbackCalled: true }, toJSON: [Function: responseToJSON], caseless: Caseless { dict: [Object] }, body: '<!DOCTYPE html><meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">Error 404 (Not Found)!!1

40 4. That's an error.

The requested URL was not found on this ser ver. That's all we know.

' } }`

SOF3 commented 4 years ago

It seems that the API no longer works without creating a valid cookie. It seems you need to access some other endpoint first to create such a valid cookie.

SOF3 commented 4 years ago

It seems that you would get a rate limit error without the __Secure-3PSID cookie.