Twitter的节点回复脚本实际没有回复(Node reply script for twitter

2019-09-30 10:13发布

这Twitter的脚本可以鸣叫当前选定的用户,一旦他们的鸣叫,但不是真正回答鸣叫下,它的鸣叫它作为一个独立的新的鸣叫。 我怎样才能得到它实际上回答,而不是作出新的鸣叫? 我使用的Twit API: https://github.com/ttezel/twit

下面是我有:

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

var Twit = require('twit');

var config = require('./config');
var T = new Twit(config);

//Setting up a user stream
var stream = T.stream('user');

stream.on('tweet', tweetEvent);

function tweetEvent(eventMsg) {

   var replyto = eventMsg.user.screen_name;
   var text = eventMsg.text;
   var from = eventMsg.user.screen_name;

   console.log(replyto + ' '+ from);

   if (replyto =='other user's handle') {
    var newtweet = '@' + from + ' Hello!';
    tweetIt(newtweet);
   }

}

function tweetIt(txt) {

    var tweet = {
     status: txt
     }

    T.post('statuses/update', tweet, tweeted);

    function tweeted(err, data, response) {
      if (err) {
        console.log("Something went wrong!");
      } else {
        console.log("It worked!");
      }
    }
}

Answer 1:

为了答复中使用Twitter的API鸣叫对话展现出来,你需要以下条件:

// the status update or tweet ID in which we will reply
var nameID  = tweet.id_str;

此外,还需要为参数in_reply_to_status_idtweet状态。 看到更新下面的代码,它现在应该保持对话:

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

var Twit = require('twit');

var config = require('./config');
var T = new Twit(config);

//Setting up a user stream
var stream = T.stream('user');

stream.on('tweet', tweetEvent);

function tweetEvent(tweet) {
    var reply_to = tweet.in_reply_to_screen_name;
    var text       = tweet.text;
    var from       = tweet.user.screen_name;
    var nameID     = tweet.id_str;
    // params just to see what is going on with the tweets
    var params     = {reply_to, text, from, nameID};
    console.log(params);

    if (reply_to === 'YOUR_USERNAME') {
        var new_tweet = '@' + from + ' Hello!';
        var tweet = {
            status: new_tweet,
            in_reply_to_status_id: nameID
        }

        T.post('statuses/update', tweet, tweeted);

        function tweeted(err, data, response) {
            if (err) {
                console.log("Something went wrong!");
            } else {
                console.log("It worked!");
            }
        }
    }
}


文章来源: Node reply script for twitter does not actually reply