I am trying to upload an image to twitter account using twitter's media upload api. I am using node-twitter
module for nodejs.
This is the code i am using
fs.writeFile("out.png", base64String, 'base64', function (err) {
console.log(err);
});
var data = fs.readFileSync("out.png");
// Make post request on media endpoint. Pass file data as media parameter
client.post('media/upload', {media: data}, function(error, media, response){
if (!error) {
// If successful, a media object will be returned.
console.log(media);
// Lets tweet it
var status = {
status: 'I am a tweet',
media_ids: media.media_id_string // Pass the media id string
}
client.post('statuses/update', status, function(error, tweet, response){
if (!error) {
console.log(tweet);
}
});
}
else{
console.log(error);
}
});