使用twit和Node.js回复推文 [英] Replying to a tweet using twit and Node.js
问题描述
我正在使用Twit Node.js API. 我想做的是回复与某个关键字匹配的推文.我希望我的回复推文显示在下面的其他推文中.就像您通过应用或网站进行回复时一样.
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.
我要做的代码在这里:
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帐户,但未回复该推文应该被回复的情况.
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.
为什么不起作用?
是的,我尝试写入in_reply_to_status_id_str,并且尝试将tweet.id_str设置为字符串.
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?
谢谢!
我的响应JSON在这里:
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,
如果您需要更多的响应式JSON,请告诉我.
If you need more of the respone JSON let me know.
推荐答案
解决方案是在响应json的状态中包含对tweet.user.screen_name的提及. 像这样工作:
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);
}
);
}
这篇关于使用twit和Node.js回复推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!