问题
I am using the Twit Node.js API. What I am trying to do is reply to a tweet that matches a certain keyword. I want my reply tweet to show up within the other tweet underneath. Like when you reply via app or website.
My code to do that is here:
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);
}
);
}
The status is written correctly to the reply JSON but in_reply_to_status_id remains null. The tweet is posted to the bots account but not in reply to the tweet is is supposed to be replying to.
Why dos it not work?
And yes I have tried to write to in_reply_to_status_id_str and I have tryed to make the tweet.id_str a string.
I there anyone who knows what I am missing?
Thank you!
My response JSON is here:
{ 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,
If you need more of the respone JSON let me know.
回答1:
The solution is to include a mention to tweet.user.screen_name into the status of the response json. Like this it works:
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);
}
);
}
来源:https://stackoverflow.com/questions/44669859/replying-to-a-tweet-using-twit-and-node-js