I used https://github.com/oauth-io/oauth-js to handle API request
OAuth.initialize('xxxxxxxxxxxx');
OAuth.popup('twitter')
.done(function (result) {
result.post('https://upload.twitter.com/1.1/media/upload.json', {
data: {
media_data: xxxxxxxxxxxxxxx //base64-encoded string
}
})
.done(function (response) {
//this will display the id of the message in the console
console.log(response.media_id);
OAuth.popup('twitter')
.done(function (result) {
result.post('https://api.twitter.com/1.1/statuses/update.json', {
data: {
status: 'test',
media_ids: response.media_id
}
})
.done(function (response) {
//this will display the id of the message in the console
console.log(response);
})
.fail(function (err) {
//handle error with err
});
})
.fail(function (err) {
//handle error with err
});
})
.fail(function (err) {
//handle error with err
});
})
.fail(function (err) {
//handle error with err
});
Result: I can receive the media_id, means image is uploaded successfully (1st endpoint). But I got ‘400 Bad Request’ error for the 2nd endpoint.
Any suggestion is appreciated.