Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm trying to reply to a tweet using Twit on Node.js

Not sure how to input the in_reply_to_status_id.

It's tweeting out fine, just not replying to the tweet with the mention in it.

The in_reply_to_status_id is part of the Twitter API, which Twit accesses, but can I use this in this context?

Any help would be greatly appreciated.

Here's the code:

var stream = T.stream('statuses/filter', { track: '@example'});

io.on('connection', function (socket) {
  socket.on('chat message', function (msg) {
    console.log('message: ' + msg);
    P.post('statuses/update', { status: '@example' + ' ' + msg}, function (err, data, response) {
      socket.emit('info', data.text);
      socket.emit('userPic', data.user.profile_image_url);
      console.log(data.user.profile_image_url);
    });
  });

  stream.start();

  stream.on('tweet', function (tweet) {
    console.log(tweet);
    // console.log('listening to tweets');

    if (tweet.text.indexOf('@example') > -1) {
      console.log("there is a tweet");
      var number = Date.now();
      var reply = replies[Math.floor(Math.random() * replies.length)];
      var name = '@' + tweet.user.screen_name;
      T.post('statuses/update', {in_reply_to_status_id: [name], status: reply + ' ' + number + ' ' + name}, function (err, data, response) {
        console.log(reply + number);
        socket.emit('reply', data.text);
      });
    }
  });
});
like image 279
UXWill Avatar asked Oct 12 '15 09:10

UXWill


People also ask

Why can't I reply to a tweet on Twitter?

Twitter Recipient May Have Blocked You. Twitter gives users the option to block accounts that they may find disruptive or abusive. If your account has been blocked, you can't send direct messages, reply to tweets, and view the user's profile.


1 Answers

The user name ID string was not being parsed correctly. The solution:

var nameID = tweet.id_str;

var name = tweet.user.screen_name;

T.post('statuses/update', {in_reply_to_status_id: nameID, status: reply + ' ' + number + ' @' + name}, function(err, data, response) { 
like image 131
UXWill Avatar answered Sep 28 '22 17:09

UXWill