在 Nodejs 中开发推特机器人时循环回复
Looping reply when developer twitter bot in Nodejs
我正在做一个项目,我有一个 Twitter 机器人可以回复其帐户中的每条推文。
这是我的代码:
var replybot = function() {
//The word that we are going to search in tweets
var word = 'hello';
//Variables to store the twitter user id and screen name to make a reply
var id_str, screen_name;
console.log('Bot started looking for the word ' + word + '.');
stream.on('tweet', tweetEvent );
function tweetEvent(tweet) {
var info_text = tweet.text;
if (info_text.indexOf(word) > -1) {
console.log(tweet.text); //Displays the tweet with the word
//We store the twitter id and the user screen name to make a reply
id_str = tweet.id_str;
screen_name = tweet.user.screen_name;
console.log('need do it once');
//Now we are going to reply the tweet
Twitter.post('statuses/update', {in_reply_to_status_id: id_str,
status: '@' + screen_name + ' I think you mean "goodbye"'},
function(error, tweet, response){
if(error) {
console.log(' Error');
}
else{
console.log('. Success!!!');
} // Tweet body
});
}
}
console.log('done');
}
replybot();
// 'reply' a tweet in every 25 minutes
setInterval(replybot, 1500000);
我正在按照这个 repo 工作:https://github.com/ttezel/twit .
但我有一个问题:当我 运行 上面的代码时,机器人在一条推文上回复了很多次,我不知道为什么。
虽然我已经为这个功能设置了时间间隔。
我是 node 的新手,任何帮助都会很棒!谢谢
哦,很抱歉,我在这里永远循环了:
函数(错误、推文、响应)
不应该是 tweet arg
我正在做一个项目,我有一个 Twitter 机器人可以回复其帐户中的每条推文。
这是我的代码:
var replybot = function() {
//The word that we are going to search in tweets
var word = 'hello';
//Variables to store the twitter user id and screen name to make a reply
var id_str, screen_name;
console.log('Bot started looking for the word ' + word + '.');
stream.on('tweet', tweetEvent );
function tweetEvent(tweet) {
var info_text = tweet.text;
if (info_text.indexOf(word) > -1) {
console.log(tweet.text); //Displays the tweet with the word
//We store the twitter id and the user screen name to make a reply
id_str = tweet.id_str;
screen_name = tweet.user.screen_name;
console.log('need do it once');
//Now we are going to reply the tweet
Twitter.post('statuses/update', {in_reply_to_status_id: id_str,
status: '@' + screen_name + ' I think you mean "goodbye"'},
function(error, tweet, response){
if(error) {
console.log(' Error');
}
else{
console.log('. Success!!!');
} // Tweet body
});
}
}
console.log('done');
}
replybot();
// 'reply' a tweet in every 25 minutes
setInterval(replybot, 1500000);
我正在按照这个 repo 工作:https://github.com/ttezel/twit .
但我有一个问题:当我 运行 上面的代码时,机器人在一条推文上回复了很多次,我不知道为什么。 虽然我已经为这个功能设置了时间间隔。
我是 node 的新手,任何帮助都会很棒!谢谢
哦,很抱歉,我在这里永远循环了:
函数(错误、推文、响应)
不应该是 tweet arg