簡體   English   中英

使用twit和Node.js回復推文

[英]Replying to a tweet using twit and Node.js

我正在使用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保持為空。 該推文已發布到bots帳戶,但未回復該推文應該被回復的情況。

為什么不起作用?

是的,我已經嘗試寫入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);
    }
  );
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM