【问题标题】:Node.js twitter bot to only retweet parent tweetsNode.js twitter bot 仅转发父推文
【发布时间】:2018-05-29 06:04:44
【问题描述】:

我正在尝试创建一个 twitter 机器人来仅转发父推文(IE 不回复其他推文或页面已转发的内容),我已设法阻止该机器人转发推文,但找不到任何关于如何停止的信息它转发对其他推文的回复,有人可以帮忙吗?

/requires twit module
var twit = require('twit');
//require the config.js file
var config = require('./config.js');
//pass key values from config to twit to allow it to tweet ect
var Twitter = new twit(config);

//query for tweets
var retweet = function() {
  var params = {
    //q is query, this one looks for tweets from city that are not retweets
    q: 'from:@officialbantams -RT',
    //makes sure to only retweet english twit
    lang: 'en'
    //I've commented this out but it filters for only retweeting a tweet posted since the last time the function ran
    //result_type: 'recent',
  } 

 // for more parametes, see: 
https://dev.twitter.com/rest/reference/get/search/tweets

    Twitter.get('search/tweets', params, function(err, data) {
      // if there no errors
        if (!err) {
          // grab ID of tweet to retweet
            var retweetId = data.statuses[0].id_str;
            // Tell TWITTER to retweet
           Twitter.post('statuses/retweet/:id', {
            id: retweetId
            //post in console that a tweet has been retweeted
        }, function(err, response) {
            if (response) {
                console.log('Retweeted!!!');
            }
            // if there was an error while tweeting
            if (err) {
                console.log('Something went wrong while RETWEETING... Duplication maybe...');
            }
        });
    }
    // if unable to Search a tweet
    else {
      console.log('Something went wrong while SEARCHING...');
    }
});
}

// grab & retweet as soon as program is running...
retweet();
// retweet in every 50 minutes (time is in ms so 100*60*number of minutes wanted
setInterval(retweet, 50*60*100);

【问题讨论】:

    标签: javascript node.js twitter


    【解决方案1】:

    知道了:

    // Get the tweet Id from the returned data
    var id = data.statuses[i].id_str;
          // Tell TWITTER to retweet
          T.post('statuses/retweet/' + id, {}, function(err, response) {
               // If the retweet fails, log the error message
               if(err){
                    console.log(err[0].message);
                }
                // If the favorite is successful, log the url of the tweet
                else{
                    let username = response.user.screen_name;
                    let tweetId = response.id_str;
                    console.log('Retweeted: ', `https://twitter.com/${username}/status/${tweetId}`)
                }
            });
    

    【讨论】:

      猜你喜欢
      • 2019-04-10
      • 2019-01-13
      • 2016-07-07
      • 2011-04-19
      • 2013-03-26
      • 2013-02-06
      • 2019-06-11
      • 2022-10-05
      • 2022-01-05
      相关资源
      最近更新 更多