Uploading media files and text status from javascript/Jquery twitter

1.1k Views Asked by At

How can i upload image and status both to twitter from client side only .I am using Oauth.io and Phonegap .If somebody know about this please reply me as soon as possible .

1

There are 1 best solutions below

0
On

Take a look at this jsfiddle: http://jsfiddle.net/6Jx84/12/

OAuth.popup("twitter").then(function(result) {
    var data = new FormData();
    data.append('status', 'This is a test');
    data.append('media[]', b64toBlob(logo), 'logo.png');

    return result.post('/1.1/statuses/update_with_media.json', {
        data: data,
        cache:false,
        processData: false,
        contentType: false
    });
}).done(function(data){
    //todo once the image is sent
}).fail(function(e){
    //todo if an error occured
});

It sends a tweet with the status "This is a test" and with the OAuth.io's logo

It uses the endpoint /1.1/statuses/update_with_media.json of the Twitter API: https://dev.twitter.com/rest/reference/post/statuses/update_with_media