我试图创建一个推特机器人仅转发父推文(即未回复其他推文或该页面已转发的内容),我设法停止了该机器人推文转发,但找不到任何方法来阻止其转发推文。其他推文,有人可以帮忙吗?

/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);

最佳答案

得到它了 :

// 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}`)
            }
        });

关于javascript - Node.js Twitter Bot仅转推父Tweets,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46051696/

10-12 12:56