admin管理员组文章数量:1332339
I'm new to node.js so please excuse the simple question. I'm writing something standard: a rest API that goes to twitter using ntwitter and saves stuff on mysql. What I'm having trouble is disconnecting and connecting back to twitter using ntwitter.
I checked a somewhat similar question to mine but that one is still unanswered: Restarting nodejs ntwitter twitter stream with different track keywords
The question is two fold:
1) How to check if the twit.stream
is alive
2) How to kill it/manually disconnect from twitter
I'm using destroy
but that does not seem to work. The relevant part of the code is:
if (values[0] == 'newStatusAdded') {
console.log('Need to stop twitter listener');
//check if twitter stream is running
if (twit.stream) {
twit.stream.destroy;
debugger;
console.log('Stopped twitter listener');
}
thanks....
I'm new to node.js so please excuse the simple question. I'm writing something standard: a rest API that goes to twitter using ntwitter and saves stuff on mysql. What I'm having trouble is disconnecting and connecting back to twitter using ntwitter.
I checked a somewhat similar question to mine but that one is still unanswered: Restarting nodejs ntwitter twitter stream with different track keywords
The question is two fold:
1) How to check if the twit.stream
is alive
2) How to kill it/manually disconnect from twitter
I'm using destroy
but that does not seem to work. The relevant part of the code is:
if (values[0] == 'newStatusAdded') {
console.log('Need to stop twitter listener');
//check if twitter stream is running
if (twit.stream) {
twit.stream.destroy;
debugger;
console.log('Stopped twitter listener');
}
thanks....
Share Improve this question edited May 23, 2017 at 10:29 CommunityBot 11 silver badge asked Sep 28, 2012 at 5:32 icaroicaro 431 silver badge6 bronze badges 02 Answers
Reset to default 5I think you have a setup somewhere in your code like this:
twit.stream('statuses/sample', function(stream) {
stream.on('data', function (data) {
console.log(data);
});
});
Save the stream variable from within the callback, for example after stream.on()
:
twit.currentTwitStream = stream;
This is only a suggestion. Perhaps you have a central configuration object which would be a better place for the current stream object. With currentTwitStream
you can do this:
currentTwitStream.readable
is false after an error or close.currentTwitStream.destroy()
destroys the stream.
I was facing this problem too. What eventually worked for me was stream.stop()
.
.destroy()
, .disconnect()
etc brought up a variety of errors such as
.destroy
is not defined.
本文标签: javascriptHow to stop and restart a twitter stream with ntwitterStack Overflow
版权声明:本文标题:javascript - How to stop and restart a twitter stream with ntwitter - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742332422a2454960.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论