Hi,
I trying to use Twitter API to tweet the message with image (NodeJS application). But always I have the following error:
{ statusCode: 400,
data: '{"errors":[{"code":38,"message":"media parameter is missing."}]}' }
My code is the following:
twitter.oa.post('https://upload.twitter.com/1.1/media/upload.json',
twitter.access_token,
twitter.access_token_secret,
{media_data: imageBase64},
function(e, data) {
if (e) {
console.error(e);
}else {
try{
data = JSON.parse(data);
}catch (e){
console.error("Error Json : " + e);
}
console.log(data.media_id);
twitter.post('statuses/update', {status:body, media_ids:[data.media_id_string]}, "", function (e, data, res){
if (e) {
cb(e);
}else {
cb(null, data);
}
});
}
}
);
I’m also tried this one:
twitter.oa.post('https://upload.twitter.com/1.1/media/upload.json',
twitter.access_token,
twitter.access_token_secret,
{media_data: '@' + imageBase64 + ';type="image/png";filename="93993d40-89ef-11e4-9521-254a3df0c166.png"'},
function(e, data) {
if (e) {
console.error(e);
}else {
try{
data = JSON.parse(data);
}catch (e){
console.error("Error Json : " + e);
}
console.log(data.media_id);
twitter.post('statuses/update', {status:body, media_ids:[data.media_id_string]}, "", function (e, data, res){
if (e) {
cb(e);
}else {
cb(null, data);
}
});
}
}
);
As you can see from the code I upload the image in base64. In the second code I hardcoded the image type, the uploaded image have the png format.
What I’m missed? Thank you in advance.