首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Nodejs中开发twitter机器人时的循环应答

在Nodejs中开发twitter机器人时的循环应答
EN

Stack Overflow用户
提问于 2017-03-14 01:18:08
回答 1查看 46关注 0票数 0

我在一个项目中工作,我有一个twitter机器人,在它的帐户中回复每条推文。

下面是我的代码:

代码语言:javascript
复制
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);

我正在使用这个代码库:https://github.com/ttezel/twit

但我有一个问题:当我运行上面的代码时,机器人在一条tweet上回复了这么多次,我不知道为什么。虽然我已经为这个函数设置了间隔。

我是node的新手,任何帮助都是很棒的!谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-14 01:41:47

哦,很抱歉,我在这里永远有一个循环:

函数(错误、推文、响应)

不应该是tweet arg

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42769591

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档