【问题标题】:Replying to a tweet using twit and Node.js使用 twit 和 Node.js 回复推文
【发布时间】:2017-11-23 23:44:49
【问题描述】:

我正在使用 Twit Node.js API。 我要做的是回复与某个关键字匹配的推文。我希望我的回复推文显示在下面的另一条推文中。就像您通过应用程序或网站回复时一样。

我的代码在这里:

var reply = function(tweet) {
  var res = {
    status: 'This is a tweet',
    in_reply_to_status_id: tweet.id_str
  };

  twitter.post('statuses/update', res,
    function(err, data, response) {
      console.log(data);
    }
  );
}

状态已正确写入回复 JSON,但 in_reply_to_status_id 仍为空。推文发布到机器人帐户,但不回复推文应该回复。

为什么它不起作用?

是的,我已尝试写入 in_reply_to_status_id_str 并且已尝试将 tweet.id_str 设为字符串。

有人知道我错过了什么吗?

谢谢!

我的响应 JSON 在这里:

{ created_at: 'Wed Jun 21 07:44:22 +0000 2017',
  id: 877431986071142400,
  id_str: '877431986071142400',
  text: 'This is a tweet',
  truncated: false,
  entities: { hashtags: [], symbols: [], user_mentions: [], urls: [] },
  source: '<a href="https://example.com" rel="nofollow">Spatinator</a>',
  in_reply_to_status_id: null,
  in_reply_to_status_id_str: null,
  in_reply_to_user_id: null,
  in_reply_to_user_id_str: null,
  in_reply_to_screen_name: null,

如果您需要更多响应 JSON,请告诉我。

【问题讨论】:

    标签: javascript json node.js twitter


    【解决方案1】:

    解决方案是在响应 json 的状态中包含对 tweet.user.screen_name 的提及。 像这样它可以工作:

    var reply = function(tweet) {
      var res = {
        status: 'This is a tweet @' + tweet.user.screen_name,
        in_reply_to_status_id: '' + tweet.id_str
      };
    
      twitter.post('statuses/update', res,
        function(err, data, response) {
          console.log(data);
        }
      );
    }
    

    【讨论】:

      猜你喜欢
      • 2021-05-13
      • 2016-01-09
      • 2017-07-19
      • 2020-10-04
      • 2014-05-04
      • 2019-04-10
      • 2020-10-11
      • 2015-03-13
      • 2020-07-24
      相关资源
      最近更新 更多