Search code examples
node.jstwittertwitter-streaming-api

Can not use "follow" in the streaming api in ntwitter. Recieving Unspecified 'error' event


I need to stream tweets from a single twitter account but I'm not sure what I'm doing wrong. When using 'track' the stream works fine (streaming trending topics). But when I use 'follow' the code breaks.

I'm using the ntwitter module.

This is the code:

var twitter = require('ntwitter');

var twit = new twitter({
  consumer_key: 'deleted',
  consumer_secret: 'deleted',
  access_token_key: 'deleted',
  access_token_secret: 'deleted'
});


twit.stream('statuses/filter', { follow:'@tbottt' }, function(stream) {
    stream.on('data',function(data){
      console.log(data);
    });
});

I get this error

Error: Uncaught, unspecified 'error' event.
    at EventEmitter.emit (events.js:68:15)
    at ClientRequest.Twitter.stream (F:\Dropbox\work\socketio\node_modules\ntwitter\lib\twitter.js:251:14)
    at ClientRequest.EventEmitter.emit (events.js:88:17)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (http.js:1455:7)
    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:111:23)
    at CleartextStream.socketOnData [as ondata] (http.js:1366:20)
    at CleartextStream.CryptoStream._push (tls.js:492:27)
    at SecurePair.cycle (tls.js:846:20)
    at EncryptedStream.CryptoStream.write (tls.js:227:13)
    at Socket.ondata (stream.js:38:26)

Solution

  • A little late I know, but I found this question after having the same problem myself.

    I discovered that you must use the twitter user's ID and not the screen name, in a follow request.

    There are a few websites which claim to offer a quick twitter username -> ID search, but none of them worked for me. Instead, I found that if you view the source code on a page containing a tweet from the user and search for data-user-id, you will find it listed as an attribute in an HTML element (usually the second or third occurance of this contains the ID).

    Hope this helps someone.