I am really new to nodejs and javascript. I am trying to create a twitter bot that post tweets with two images. However, all implementations I have came across use single media upload that only helps with a single image file.
const Twitter = require("twitter")
const fs = require("fs")
const client = new Twitter({
consumer_key: process.env.CONSUMER_KEY,
consumer_secret: process.env.CONSUMER_SECRET,
access_token_key: process.env.ACCESS_TOKEN_KEY,
access_token_secret: process.env.ACCESS_TOKEN_SECRET
})
const imageData1 = fs.readFileSync("./quote.jpg");
const imageData2 = fs.readFileSync("./meaning.jpg"); // the second image i want to upload
client.post("media/upload", {media: imageData1}, function(error, media, response) {
if (error) {
console.log(error)
} else {
const status = {
status: "I tweeted from Node.js!",
media_ids: media.media_id_string
}
console.log(media)
client.post("statuses/update", status, function(error, tweet, response) {
if (error) {
console.log(error)
} else {
console.log("Successfully tweeted an image!")
}
})
}
})
Any help about a different approach or anything that i am doing wrong is appreciated. Cheers!