Tweet Image: 400 Bad Request

restapi
oauth
image
javascript
api

#1

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.


#2

I’m not sure, but this little detail from the documentation may be useful here?

Use the media_id_string provided in the API response from Javascript and other languages that cannot accurately represent a long integer.