Here is what I use to download media:
(I use OAuth to create Oauth authentication)
I also add /statuses/update.json to associate a new message with your media.
var oauth = require('oauth'); var fs = require('fs'); var a = new oauth.OAuth("https://twitter.com/oauth/request_token", "https://twitter.com/oauth/access_token", config.consumerKey, config.consumerSecret, "1.0", config.callbackUrl, "HMAC-SHA1"); a.post("https://upload.twitter.com/1.1/media/upload.json", oauth_access_token, oauth_access_token_secret, {media:fs.readFileSync(file_path).toString("base64")} ,"" , function (e, data, res){ if (e) { console.error(e); }else { try{ data = JSON.parse(data); }catch (e){ console.error("Error Json : " + e); } console.log(data.media_id); a.post("https://api.twitter.com/1.1/statuses/update.json", oauth_access_token, oauth_access_token_secret, {status:message,media_ids:[data.media_id_string]}, "", function (e, data, res){ if (e) { console.error(e); }else { console.log("Success"); } }); } });
Enjoy
Neige
source share