Twitter的节点回复脚本实际上并未回复 [英] Node reply script for twitter does not actually reply
问题描述
此Twitter脚本当前可以在选定用户发送推文后发推文,但实际上并未在该推文下方回复,而是将其作为独立的新推文进行推文.如何获得实际答复而不是发新推文?我正在使用Twit API: https://github.com/ttezel/twit
This twitter script can currently tweet the selected user once they tweet, but instead of actually replying underneath the tweet, it tweets it as a standalone new tweet. How can I get it to actually reply instead of make a new tweet? I'm using Twit API: https://github.com/ttezel/twit
这就是我所拥有的:
console.log('The bot is starting');
var Twit = require('twit');
var config = require('./config');
var T = new Twit(config);
//Setting up a user stream
var stream = T.stream('user');
stream.on('tweet', tweetEvent);
function tweetEvent(eventMsg) {
var replyto = eventMsg.user.screen_name;
var text = eventMsg.text;
var from = eventMsg.user.screen_name;
console.log(replyto + ' '+ from);
if (replyto =='other user's handle') {
var newtweet = '@' + from + ' Hello!';
tweetIt(newtweet);
}
}
function tweetIt(txt) {
var tweet = {
status: txt
}
T.post('statuses/update', tweet, tweeted);
function tweeted(err, data, response) {
if (err) {
console.log("Something went wrong!");
} else {
console.log("It worked!");
}
}
}
推荐答案
为了使回复显示在使用Twitter API的tweet对话中,您需要以下内容:
In order for a reply to show up in the tweet conversation using the Twitter API, you need the following:
// the status update or tweet ID in which we will reply
var nameID = tweet.id_str;
还需要状态为tweet
的参数in_reply_to_status_id
.请在下面查看您代码的更新,它现在应该保留对话:
Also needed is the parameter in_reply_to_status_id
in the tweet
status. See the updates to your code below and it should now preserve the conversation:
console.log('The bot is starting');
var Twit = require('twit');
var config = require('./config');
var T = new Twit(config);
//Setting up a user stream
var stream = T.stream('user');
stream.on('tweet', tweetEvent);
function tweetEvent(tweet) {
var reply_to = tweet.in_reply_to_screen_name;
var text = tweet.text;
var from = tweet.user.screen_name;
var nameID = tweet.id_str;
// params just to see what is going on with the tweets
var params = {reply_to, text, from, nameID};
console.log(params);
if (reply_to === 'YOUR_USERNAME') {
var new_tweet = '@' + from + ' Hello!';
var tweet = {
status: new_tweet,
in_reply_to_status_id: nameID
}
T.post('statuses/update', tweet, tweeted);
function tweeted(err, data, response) {
if (err) {
console.log("Something went wrong!");
} else {
console.log("It worked!");
}
}
}
}
这篇关于Twitter的节点回复脚本实际上并未回复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!