Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
Posts: 20
Registered: ‎12-22-2012
My Device: PlayBook
My Carrier: Verizon
Accepted Solution

Javascript library to handle Twitter's update_with_media as a function?

I have a BB10 Twitter app that's written in plain old-fashioned javascript, using jsOAuth for all Twitter calls. Works great, EXCEPT I cannot find a way to post pictures via Twitter's update_with_media, as jsOAuth won't handle it.

 

Does anyone know of a pure javascript library that can post media to Twitter, wrapping Twitter's update_with_media as a simple function call?

 

Something like: postMedia("My Status", myFilename);

 

I can find numerous libraries for node.js, python, etc. that  do it. But for the life of me, I just cannot find an ordinary javascript library that will do it. CodeBird comes close, but still isn't quite working.

BlackBerry Development Advisor
Posts: 762
Registered: ‎10-01-2009
My Device: All
My Carrier: N/A

Re: Javascript library to handle Twitter's update_with_media as a function?

I have a sample app that uses Twitter, and jsOAuth to authenticate with Twitter.  From that point you should be able to do and update_with_media.  99% of the OAuth work is just getting authorized with the service.  After that, it's just a matter of POST/GET to your desired endpoint.

 

Here's the sample: https://github.com/blackberry/BB10-WebWorks-Samples/tree/master/Twitter-OAuth-1

Contributor
Posts: 20
Registered: ‎12-22-2012
My Device: PlayBook
My Carrier: Verizon

Re: Javascript library to handle Twitter's update_with_media as a function?

The catch seems to be that jsOAuth can handle all Twitter calls *except*  update_with_media, as update_with_media wants multipart data. So I'm left trying to figure out how to POST the request manually, which gets complicated in creating headers, signatures, encoding the data, etc. Normally, jsOAuth takes care of all that messy stuff, but with update_with_media we have to do it on our own it seems.... at least when using ordinary javascript.

 

I've started trying to put it all together on my own, but it's like needing to reinvent the combusiton engine before buying a car, lol.

BlackBerry Development Advisor
Posts: 762
Registered: ‎10-01-2009
My Device: All
My Carrier: N/A

Re: Javascript library to handle Twitter's update_with_media as a function?

Ah right, sorry I forgot about that (very important) part.

 

Previously I've used PhoneGap's File Transfer API (when I wrote an app needing to upload to Twitter on BBOS).  Right now, we have the WebWorks File Transfer API although it doesn't accept custom headers just yet. 

 

Have you tried using XHR2, and creating your own request from scratch? I know you can get all the info you need from jsOauth as far as creating the signatures etc for the request, it may be just a matter of putting all the pieces together.

Contributor
Posts: 20
Registered: ‎12-22-2012
My Device: PlayBook
My Carrier: Verizon

Re: Javascript library to handle Twitter's update_with_media as a function?

Hi again and thanks! Yup, I did try the new BB10 blackberry.io.fileTransfer call at one point just to see what it could do... and it crashes (closes) my app as soon as it's executed, lol. Never saw that happen before with a BB10 app, it didn't "hang," it just closed itself everytime the function was called. I'm guessing it still needs some work Smiley Wink

 

It does look more and more like I'm going to have to do the transfer manually, as you suggest. It's just that I've read the nightmares others have had trying to do that with media uploads to Twitter, as it's apparently very picky about every little CR, etc. So I've been hoping someone else had figured it out and codified their findings in JS. I admit I'm waaay out of my realm of knowledge here when it comes to file transfers, formatting multi-part uploads, generating signatures, etc.

 

But I guess this is how/why we learn Smiley Wink