4

i am trying to use ntwitter ,node.js and socket.io for accessing twitter user stream.the twitter user stream works fine and i can get the tweets in real time.the tweets get displayed in the console using the following function.

console.log(data.text) ;

then i want push the data to the browser.this can be done using sockets.the following link shows example of a simple node.js client for twitetrs public stream.

http://www.informit.com/articles/article.aspx?p=1947699&seqNum=5

now the same doesn not work for my user stream.the data gets displayed in the console without any problem but if i try to push it to the browser i get error.

Error: Uncaught, unspecified 'error' event.
at EventEmitter.emit (events.js:73:15)
at EventEmitter.receive (C:\Users\tweeple\Desktop\ho
odules\ntwitter\lib\parser.js:41:14)
at IncomingMessage.Twitter.stream (C:\Users\prathamesh\
e03\node_modules\ntwitter\lib\twitter.js:266:14)
at IncomingMessage.EventEmitter.emit (events.js:96:17)
at IncomingMessage._emitData (http.js:359:10)
at HTTPParser.parserOnBody [as onBody] (http.js:123:21)
at CleartextStream.socketOnData [as ondata] (http.js:13
at CleartextStream.CryptoStream._push (tls.js:526:27)
at SecurePair.cycle (tls.js:880:20)
at EncryptedStream.CryptoStream.write (tls.js:267:13)

the code is:

var app = require('express').createServer(),
twitter = require('ntwitter'),
io = require('socket.io').listen(app);
app.listen(3000);

var twit = new twitter({
consumer_key: 'key',
consumer_secret: 'consumer secret',
access_token_key: 'token',
access_token_secret: 'token secret'
});

twit.stream('user', {track:'nodejs'}, function(stream) {
stream.on('data', function (data) {
io.sockets.emit('tweet',{
  user: data.user.screen_name,
  text: data.text
});
});
});
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});

please help me.

tweeper
  • 352
  • 1
  • 4
  • 16

1 Answers1

1

Handling the error may work:

stream.on('error', function(error) {
    console.error(error);
});
hacklikecrack
  • 1,360
  • 1
  • 16
  • 20