我正在使用Twit 模块在 AngularJS 应用程序中显示 Twitter 流。我想在用户单击停止按钮时提供关闭流的选项。
处理流式传输的脚本:
var Twit = require('twit');
var T = new Twit({
consumer_key : 'XXX',
consumer_secret : 'XXX',
access_token : 'XXX',
access_token_secret : 'XXX'
});
function streamingHashtag(streamBool)
{
var stream = T.stream('statuses/filter', { track: 'test' });
stream.on('tweet', function (tweet) {
console.log(tweet);
});
stream.on('disconnect',function(disconnectMessage){
stream.stop();
});
if(streamBool == false){
stream.stop();
console.log('Stream stopped by user');
}
}
按下按钮停止后,控制台输出以下错误并且流继续:
message: "Cannot call method 'abort' of undefined", stack: "TypeError: Cannot call method 'abort' of undefined…es\connect\lib\middleware\methodOverride.js:37:5)"}
message: "Cannot call method 'abort' of undefined"
stack: "TypeError: Cannot call method 'abort' of undefined? at OARequest.stop ([localhost]\node_modules\twit\lib\oarequest.js:110:16)? at Object.streamingHashtag ([localhost]\server\library\twitter.js:40:10)? at exports.twitterStream ([localhost]\server\routes\index.js:11:10)? at callbacks ([localhost]\node_modules\express\lib\router\index.js:161:37)? at param ([localhost]\node_modules\express\lib\router\index.js:135:11)? at pass ([localhost]\node_modules\express\lib\router\index.js:142:5)? at Router._dispatch ([localhost]\node_modules\express\lib\router\index.js:170:5)? at Object.router ([localhost]\node_modules\express\lib\router\index.js:33:10)? at next ([localhost]\node_modules\express\node_modules\connect\lib\proto.js:190:15)? at Object.methodOverride [as handle] ([localhost]\node_modules\express\node_modules\connect\lib\middleware\methodOverride.js:37:5)"
我正在运行最新版本(package.json 说“版本”:“1.1.11”),经过调查,我发现 OARequest.js 中的停止函数指向 abort()。
我在这里做错了什么?