Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Support streaming responses #29

Open
bytespider opened this issue Jan 4, 2012 · 11 comments
Open

Support streaming responses #29

bytespider opened this issue Jan 4, 2012 · 11 comments

Comments

@bytespider
Copy link
Owner

A feature request: I'm playing with Twitter's Streaming API, which
requires OAuth for connecting. Problem is jsOAuth does not support
streaming responses.

The get method currently looks at readystate == 4, which is the
completed state. A streaming response never does complete. So I need to
write my own request method, that does that magic I want. Problem is,
the request method is HUGE, and while I only need to monkey patch a
small part of the code, the size of the request method makes me have to
copy/paste large chunks of code. So it all sums up to this: I would like
request method to be split up into several smaller methods, so I can
write a method that works with streaming.

@EmilStenstrom
Copy link

To clarify my use-case even more:

I would like to listen to readystate == 3, and read the partial response from xhr.responseText. This does not work in IE, so I don't expect support for this in jsOAuth. What I would like, is a way to write the plumbing for that myself, and somehow just use the OAuth signing from jsOAuth.

@bytespider
Copy link
Owner Author

How about something like:

    var xhr = oauth.signedXMLHttpRequest({
        method: "GET",
        url: "http://bytespider.eu",
        data: {message: "this is cool"},
        headers: {"Content-Type": "application/x-www-form-urlencoded"}
    });

Clearly this method you'd have to handle some stuff yourself like how to encode any data you need to send.

Alternatively:
I can add readystatechange as an option to oauth.request() which would replace the built in one.

@EmilStenstrom
Copy link

Yes, the first alternative sounds like a great one!

@EmilStenstrom
Copy link

Here's a working example of what I'm trying to do: http://stackoverflow.com/a/8752044/117268 - I just need OAuth instead of Basic Auth now.

@sfrenot
Copy link

sfrenot commented Feb 14, 2012

Hello guy, I have made the oauth work with streaming twitter. It is mostly working from the origin but there were some problems.

I had to remove the header callback, since keys were not well calculated.

headerParams = {
//'oauth_callback': oauth.callbackUrl,
...

As, you said I had to manage the stream away from this condition :
if (xhr.readyState === 4) {
I put some very bad stuff before, just to see that it works, such as
xhr.onreadystatechange = function () {
success(xhr);
if (xhr.readyState === 4) {

@bytespider
Copy link
Owner Author

I'm sorry I don't understand. Can you be clearer? Please submit a pull request if you have code you would like to share.

@bguiz
Copy link

bguiz commented Jul 7, 2012

+1 vote for this as well - I asked this question prior to finding this issue: http://stackoverflow.com/questions/11374771/how-to-make-twitter-streaming-apis-work-with-jsoauth

@bytespider
Copy link
Owner Author

jsOAuth 2.0 will support a way to craft and use your own XHR objects and callbacks.

@bguiz
Copy link

bguiz commented Jul 9, 2012

@bytespider Thanks for the update - looking forward to 2.0!
Any word on the rough timeline to expect for this?

@bytespider
Copy link
Owner Author

Sadly not. I may do a pre-release without OAuth 2.0 support just to get the code out there.

@bguiz
Copy link

bguiz commented Jul 9, 2012

@bytespider Yeah that pre-release sounds like a great idea!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants