bytespider / jsOAuth

JavaScript implimentation of the OAuth protocol. Currently supports version 1.0 (RFC5849) of the specification. Node.js & CommonJS compatible.
http://bytespider.github.com/jsOAuth/
MIT License
557 stars 109 forks source link

Twitter 401 Unauthorized for get/post methods after access_token is saved #55

Closed ldeluca closed 9 years ago

ldeluca commented 9 years ago

I call the oauth/request_token method and get the requestParams. Then I have the users authorize using oauth/authorize. I get and set the verifier oauth.setVerifier. Then I call oauth/access_token with the verifier and the requestParams... which successfully returns the access token and access token secret. I set the access token oauth.setAccessToken([accessParams.oauth_token, accessParams.oauth_token_secret]); Then call a method to get a home_timeline.

Failed to load resource: the server responded with a status of 401 (Unauthorized) https://api.twitter.com/1/statuses/home_timeline.json

I tried other twitter endpoints and all of them throw the unauthorized error. Printing the access token it looks like it's set just fine.

I'm using the example from: https://gist.github.com/funkatron/979955

Which has: function getHomeTimeline() { oauth.get('https://api.twitter.com/1/statuses/home_timeline.json/',

            function(data) {
                alert('got the timeline: ' + JSON.stringify(data));
            },

            function(data) { alert('lame'); console.dir(data); }
        );          
    }

Any idea why I'm getting a 401 unauthorized? Using jsoauth version 1.3.7

ldeluca commented 9 years ago

Looks like my problem was using version 1 instead of 1.1. Also didn't like the trailing "/" in my request. I tried to get at the streaming response and that also throws the 401 unauthorized error. But I saw other issues that the streaming just wasn't supported right now.

bytespider commented 9 years ago

Sorry for the delay in my reply. I'm glad you were able to find the answers you needed. Feel free to ask if there is anything else you'd like help with.

ldeluca commented 9 years ago

@bytespider any news on using the twitter streaming api's with your code yet? I'd LOVE to use them (even if you have some untested code) for an upcoming demo I'm doing for a conference.

bytespider commented 9 years ago

@ldeluca the problem is that I use an XMLHttpRequest like library and also check for ReadyState == Done.

If you're open to a bit of manual grind, you might try https://github.com/mikeal/request#oauth-signing. Its much lower level. As its designed for node, so you should be able to .pipe() the streaming response to your parser.

bytespider commented 9 years ago

I will definitely take a look again at using a request model that will allow jsOAuth to provide streaming support.

ldeluca commented 9 years ago

@bytespider I wrote an apache cordova plugin for the streaming api: http://plugins.cordova.io/#/package/com.lisaseacat.twitter It uses your jsoauth and twitter4j. Only works for Android (as of now) but maybe it'll help some other developers out.