[英]How to reply to someone's tweet using node.js twit?
我正在嘗試制作一個機器人,每次他們發推文時都會用一張圖片來回應我朋友的推文。 一切正常,但我無法讓它回復原始推文,只能回復。 有沒有辦法做到這一點?
function tweetEvent(tweetMsg) {
var replyto = tweetMsg.in_reply_to_screen_name;
var from = tweetMsg.user.screen_name;
var id = tweetMsg.id_str;
if(from === "---"){
var b64content = fs.readFileSync('media/img.png', {
encoding: 'base64'
})
T.post('media/upload', {
media_data: b64content
}, uploaded);
function uploaded(err, data, response) {
var mediaIdStr = data.media_id_string;
var params = {
status,
in_reply_to_status_id: id,
media_ids: [mediaIdStr]
}
//! Post tweet
T.post('statuses/update', params, tweeted);
};
function tweeted(err, reply) {
if(err) {
console.log(err);
console.log();
console.log("Error.");
} else {
console.log("tweeted");
}
}
}
}
我希望它回復原始推文,唯一可行的方法是使用:
if(replyto === "---"){
}
但這並沒有達到我想要的效果。
我可以用if (tweet.in_reply_to_screen_name === null) tweetEvent(tweet);
const tweets = [
{
created_at: "Wed Feb 10 03:50:17 +0000 2021",
id: 1359348938248183800,
id_str: "1359348938248183809",
text: "reply test 1290hHhbjikl",
truncated: false,
entities: [Object],
metadata: [Object],
source:
'<a href="https://mobile.twitter.com" rel="nofollow">Twitter Web App</a>',
in_reply_to_status_id: 1359339654080790500,
in_reply_to_status_id_str: "1359339654080790530",
in_reply_to_user_id: 1167232572067369000,
in_reply_to_user_id_str: "1167232572067368960",
in_reply_to_screen_name: "OpenDreamPhone",
user: [Object],
geo: null,
coordinates: null,
place: null,
contributors: null,
is_quote_status: false,
retweet_count: 0,
favorite_count: 0,
favorited: false,
retweeted: false,
lang: "in",
},
{
created_at: "Wed Feb 10 03:13:23 +0000 2021",
id: 1359339654080790500,
id_str: "1359339654080790530",
text: "this is a test. 1290hHhbjikl",
truncated: false,
entities: [Object],
metadata: [Object],
source:
'<a href="https://mobile.twitter.com" rel="nofollow">Twitter Web App</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,
user: [Object],
geo: null,
coordinates: null,
place: null,
contributors: null,
is_quote_status: false,
retweet_count: 0,
favorite_count: 0,
favorited: false,
retweeted: false,
lang: "en",
},
];
const tweetEvent = (tweet) => {
var b64content = fs.readFileSync("twitt/img.png", {
encoding: "base64",
});
T.post(
"media/upload",
{
media_data: b64content,
},
uploaded
);
function uploaded(err, data, response) {
var mediaIdStr = data.media_id_string;
var params = {
status: "hi",
in_reply_to_status_id: tweet.id_str,
media_ids: [mediaIdStr],
};
//! Post tweet
T.post("statuses/update", params, tweeted);
}
function tweeted(err, reply) {
if (err) {
console.log(err);
console.log();
console.log("Error.");
} else {
console.log(reply);
console.log("tweeted");
}
}
};
tweets.forEach((tweet) => {
if (tweet.in_reply_to_screen_name === null) tweetEvent(tweet);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.