You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my project I'm using Twitter API user timeline (both v1 and v2) and filtered stream (v2) with needle successfully, but I can't get the v1 version of filtered stream (statuses/filter) working with needle.
I feel clueless, as needle's streaming works fine with API v2 (just like the official example) and I've tested the authentication part (OAuth) of my v1 code and verified that it works well (response code: 200) - yet I'm not getting any data from the stream.
I even tried finding the problem by setting up Fiddler as a proxy of needle, but I saw nothing strange.
I've created an extracted, stand alone version of the v1 streaming module, hoping that someone can spot the issue/bug.
constuuid=require('uuid');constoauth=require('oauth-sign');constneedle=require('needle');constkeys={twitter: {consumerKey: '<your-consumerKey>',//API KeyconsumerSecretKey: '<your-consumerSecretKey>',//API Secret KeyoauthToken: '<your-oauthToken>',//Access TokenoauthTokenSecret: '<your-oauthTokenSecret>',//Access Token Secret}};conststreamURL='https://stream.twitter.com/1.1/statuses/filter.json';constapiParams={'track': 'pizza',};functiongetAuthHeader(){consttimestamp=Date.now()/1000;constnonce=uuid.v4().replace(/-/g,'');letoauthParams={'oauth_consumer_key': keys.twitter.consumerKey,'oauth_nonce': nonce,'oauth_signature_method': 'HMAC-SHA1','oauth_timestamp': timestamp,'oauth_token': keys.twitter.oauthToken,'oauth_version': '1.0'};letmergedParams={ ...apiParams, ...oauthParams};oauthParams['oauth_signature']=oauth.hmacsign('POST',streamURL,mergedParams,keys.twitter.consumerSecretKey,keys.twitter.oauthTokenSecret);returnObject.keys(oauthParams).sort().map(function(k){returnk+'="'+oauth.rfc3986(oauthParams[k])+'"';}).join(', ');}functionstreamConnect(retryAttempt){conststream=needle.post(streamURL,apiParams,{headers: {'Authorization': `OAuth ${getAuthHeader()}`,'Content-Type': 'application/x-www-form-urlencoded',},timeout: 20000});stream.on('header',(statusCode,headers)=>{console.log(`Status: ${statusCode} `+`(${statusCode===200 ? 'OK' : 'ERROR'})`);}).on('data',data=>{//never receiving any data ???console.log('data received:');console.log(data);}).on('err',error=>{// This reconnection logic will attempt to reconnect when a disconnection is detected.// To avoid rate limits, this logic implements exponential backoff, so the wait time// will increase if the client cannot reconnect to the stream. letretryTimeout=2**retryAttempt;console.warn(`A connection error occurred: ${error.message}. Reconnecting in ${retryTimeout/1000} seconds...`)setTimeout(()=>{streamConnect(++retryAttempt);},retryTimeout);});returnstream;}streamConnect(0);
The text was updated successfully, but these errors were encountered:
I'm using Node v14.15.5 and I've tried v2.9.0 and v3.0.0 too, but none of them worked with this test script.
Still don't know why, as this code works with Twitter API v2 and other libraries still work with the v1.1 API.
In my project I'm using Twitter API user timeline (both v1 and v2) and filtered stream (v2) with needle successfully, but I can't get the v1 version of filtered stream (statuses/filter) working with needle.
I feel clueless, as needle's streaming works fine with API v2 (just like the official example) and I've tested the authentication part (OAuth) of my v1 code and verified that it works well (response code: 200) - yet I'm not getting any data from the stream.
I even tried finding the problem by setting up Fiddler as a proxy of needle, but I saw nothing strange.
I've created an extracted, stand alone version of the v1 streaming module, hoping that someone can spot the issue/bug.
The text was updated successfully, but these errors were encountered: