【问题标题】:Twitter bot with node.js filter retweets带有 node.js 过滤器转发的 Twitter 机器人
【发布时间】:2017-11-28 01:46:54
【问题描述】:

我正在制作一个基本的 Twitter 机器人,它将在推文中搜索某个单词并回复它们。

问题是它同时回复推文和转推,但我希望它只回复推文。如何从流中过滤转推?

我试过{ track: 'hello -filter:retweets'},但没用。

console.log('The bot is starting');


var ntwitter = require('ntwitter');

var bot = new ntwitter({
  consumer_key: '---',
  consumer_secret: '---',
  access_token_key:  '---',
  access_token_secret: '---'
});

var callback = function handleError(error) {
   if (error) {
   console.error('response status:', error.statusCode);
   console.error('data:', error.data);
  }
};

function startStreaming() {

  bot.stream('statuses/filter', { track: 'hello'}, function(stream) {

    console.log('Listening for Tweets...');

    stream.on('data', function(tweet) {

      if (tweet.text.match(/hello/)) {

          bot.updateStatus('@' + tweet.user.screen_name + 'hello' , {in_reply_to_status_id: tweet.id_str} , callback);
          console.log("done")
       }
      });

     });
}


startStreaming();

【问题讨论】:

    标签: node.js twitter bots


    【解决方案1】:

    检查retweeted_status

    stream.on('data', function (tweet) {
        if (!tweet.retweeted_status) {
        //...
    

    我还写了一个类似 bot 的小推特,也许对你有帮助: https://github.com/abimelex/twivorite

    【讨论】:

      猜你喜欢
      • 2019-07-18
      • 2017-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-03
      • 1970-01-01
      • 2022-06-10
      • 2020-08-09
      相关资源
      最近更新 更多