我有以下节点js代码
var http= require('http').createServer();
var util = require('util');
var twitter=require('ntwitter');
http.listen(3000);
var twit= new twitter({
consumer_key: 'consumer_key',
consumer_secret: 'consumer_secret',
access_token_key: 'access_token_key',
access_token_secret: 'access_token_secret'
});
console.log('Connected to twittere');
twit.stream(
'statuses/filter',
{ track: ['awesome', 'cool', 'rad', 'gnarly', 'groovy'] },
function(stream) {
stream.on('data', function(tweet) {
console.log(tweet.text);
});
}
);
console.log('after Connected');
执行代码后我得到错误:
$ node twitter1 连接到twittere 连接后
events.js:74 抛出TypeError('未捕获,未指定"错误"事件。');
^
TypeError:未捕获,未指定"错误"事件
at TypeError (<anonymous>)
at EventEmitter.emit (events.js:74:15)
at ClientRequest.<anonymous> (/Users/atishshinde/Documents/RIT/GIS/node_modules/ntwitter/lib/twitter.js:251:14)
at ClientRequest.EventEmitter.emit (events.js:95:17)
at HTTPParser.parserOnIncomingClient [as onIncoming] (http.js:1688:21)
at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:121:23)
at CleartextStream.socketOnData [as ondata] (http.js:1583:20)
at CleartextStream.read [as _read] (tls.js:507:12)
at CleartextStream.Readable.read (_stream_readable.js:320:10)
at EncryptedStream.write [as _write] (tls.js:366:25)
我不确定这里出了什么问题?
它是一个简单的代码..请建议..
谢谢。
答案 0 :(得分:0)
看起来您收到了错误回复,而不是您期望的推文对象。记录Tweet.text的推文,看看它的内容