javascript - 使用 twit 和 Node.js 回复推文

标签 javascript json node.js twitter

我正在使用 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,请告诉我。

最佳答案

解决方案是在响应 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);
    }
  );
}

关于javascript - 使用 twit 和 Node.js 回复推文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44669859/

相关文章:

javascript - 呈现 html.erb 文件时未定义的方法 `formats'

javascript - AngularJS View 未加载

json - 尝试从 JSON URL 接收数据并将其放入 UILabel 中

Node.js : How can I add meta data to an audio file?

javascript - 如何将匿名帐户转换为永久帐户

javascript - angularjs指令使用 Controller 作为vm而不是作用域

json - 在 json 数组上迭代 Mediator

javascript - Gallery3 - 保存失败后重新加载页面

node.js - 从 Node.js 中的 MongoClient 执行服务器端函数

android - Appcelerator Titanium 3 安卓模拟器环境错误