javascript - 如何使用 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);
});
推荐阅读
- verilog - 在 Verilog 中为多个变量分配一个值的正确语法是什么?
- c# - C#如何只将列表中的一个值返回到ComBox?而不是所有
- python - 排序不适用于python中数据框的长列列表
- c# - 为什么 Newtonsoft.Json 无法解析符号“DeserializeObject”?
- powershell-3.0 - Powershell Script:最快删除大文件中大量行的最佳方法是什么?
- mysql - MySQL 使用多行的 REGEXP
- perl - 如何验证文件名?
- swift - NavigationView 顶部的额外空间
- azure-databricks - 从 DatabricksStep 注册 Azure ML 模型
- r - Reshape from long to wide according to the number of occurrence of one variable