desmondmorris / node-twitter

Client library for the Twitter REST and Streaming API's.
https://www.npmjs.com/package/twitter
MIT License
1.27k stars 237 forks source link

How upload two images? #342

Open Kevinsillo opened 4 years ago

Kevinsillo commented 4 years ago

How upload two images? Thank you

Kevinsillo commented 4 years ago

I have discovered how it is done through the official documentation of Twitter. Concatenate media_id/s with commas.

var imageOne = require('fs').readFileSync('./xxxx.jpg');
var imageTwo = require('fs').readFileSync('./yyyy.jpg');
twitter.post('media/upload', {media: imageOne}, function(error, media, response) {
    var mediaOne = media.media_id_string
    twitter.post('media/upload', {media: imageTwo}, function(error, media, response) {
        var mediaTwo = media.media_id_string
        var status = {
            status: 'Text of tweet',
            media_ids: mediaOne+','+mediaTwo // <-------------  CONCAT WITH COMMAS
        }
        console.log(status)
        twitter.post('statuses/update', status, async function(error, tweet, response) {
        });
    })
})