我正在尝试使用ntwitter,node.js和socket.io来访问Twitter用户流.推特用户流工作正常,我可以实时获取推文.推文使用以下功能显示在控制台中. console.log(data.text) ; 然后我想将数据推送到浏览器
console.log(data.text) ;
然后我想将数据推送到浏览器.这可以使用套接字完成.以下链接显示了twitetrs公共流的简单node.js客户端的示例.
http://www.informit.com/articles/article.aspx?p=1947699&seqNum=5
现在同样不适用于我的用户流.数据在控制台中显示没有任何问题,但如果我尝试将其推送到浏览器,我会收到错误.
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)
代码是:
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'); });
请帮我.
处理错误可能有效:stream.on('error', function(error) { console.error(error); });