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

Is this API still working?

Open Astraport opened this issue 6 years ago • 2 comments

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, [Symbol(connect-options)]: [Object] }, 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=3mhr_vIYOQzsBq8fxwEglUqspia0ptWAai6y4Qbb5pAcKEJSUtYP7ozqlpGjozMZj 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(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] }, _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(kNeedDrain)]: false, [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><html lang=en><meta charset=utf-8><meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width"><title>Error 404 (Not Found)!!1</title><style nonce="IfqyQwm/yLcc312ovP0+kQ">*{margin:0;padding:0 }html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;paddi ng:15px}body{color:#222;text-align:unset;margin:7% auto 0;max-width:390px;min-he ight:180px;padding:30px 0 15px;}* > body{background:url(//www.google.com/images/ errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;ov erflow:hidden}pre{white-space:pre-wrap;}ins{color:#777;text-decoration:none}a im g{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0 ;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/br anding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@ media only screen and (min-resolution:192dpi){#logo{background:url(//www.google. com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0% /100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/ googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pix el-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/ googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#log o{display:inline-block;height:54px;width:150px}</style><div id="af-error-contain er"><a href=//www.google.com><span id=logo aria-label=Google></span></a><p><b>40 4.</b> <ins>That's an error.</ins><p>The requested URL was not found on this ser ver. <ins>That's all we know.</ins></div>' } }

Astraport avatar Dec 01 '19 13:12 Astraport

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 avatar Mar 19 '20 08:03 SOF3

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

SOF3 avatar Mar 19 '20 08:03 SOF3