简体   繁体   English

我正在尝试在Node.js上使用Twit回复一条推文

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

Not sure how to input the in_reply_to_status_id. 不确定如何输入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? in_reply_to_status_id是Twit访问的Twitter API的一部分,但是我可以在这种情况下使用它吗?

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

The user name ID string was not being parsed correctly. 用户名ID字符串未正确解析。 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) { 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM