0

Application type: mobile, Titanium SDK: 3.0.2.GA, Platform & version: Android 4.0.4, Device: Android Xperia P,

i am trying to use twitter API via jsOAuth 1.3.6. all the OAuth dance goes well until I fetch request token (oAuthApi.fetchAccessToken() method). i am always getting "unauthorized" error any idea why? please see code below

oAuthApi.fetchRequestToken(function(data) {
                    //authorize
                    var authorizeUi = Ti.UI.createWebView({
                        width : Ti.UI.FILL,
                        height : Ti.UI.FILL,
                        top : 0,
                        left : 0,
                        url : data
                    });
                    authorizeUi.addEventListener('load', function(e) {                            
                        if (authorizeUi.getUrl().indexOf('twitterOauthCallback') > -1) {
                            oAuthApi.fetchAccessToken(function(data) {
                                oAuthApi.saveAccessToken();
                                oAuthApi.setAuthorised(true);
                                var accessToken = oAuthApi.getAccessToken();
                                var accessTokenSecret = oAuthApi.getAccessTokenSecret();

                               ...some other code here

                            }, function(data) {
                                alert('fetchAccessToken unauthorized error ' + data.error);
                            });
                        }
                    });                        

                }, function(data) {
                    alert('fetchRequestToken error');
                });

here is my jsOAuth initialization:

var oauth = OAuth({
        consumerKey : jsonObj.consumerKey,
        consumerSecret : jsonObj.consumerSecret,
        callbackUrl : jsonObj.callbackUrl
    });

my callback is

http://192.168.1.116:8888/callback/twitterOauthCallback.html

1- I call fetchRequestToken (ok) 2- i open the user authorization / login window (ok) 3 - enter username and password and get the callback url (ok) 4 - call fetchAccessToken (get 401 error)

below is my header:

oauth_callback = http://192.168.1.74:8888/callback/twitterOauthCallback.html
oauth_consumer_key = E3xxxxxxxxxxxxxxHfg
oauth_token = J1fxxxxxxxxxxxxxxxxxxxxxxxxxxxx20
oauth_signature_method = HMAC-SHA1
oauth_timestamp = 1365151792
oauth_nonce = 36222C667E353A51
oauth_verifier = 
oauth_version = 1.0 

any idea what might be the problem ?? i am blocked

Sameeh Harfoush
  • 610
  • 1
  • 8
  • 22

1 Answers1

1

Twitter made an abrupt and unannounced change to oauth this week: https://dev.twitter.com/discussions/16443

Looking at the header, the issue is that your oauth_verifier value is empty and the change now enforces this value. You'll get this with your callback URL as a parameter (http://192.168.1.116:8888/callback/twitterOauthCallback.html?oauth_token=xxx&oauth_verifier=xxx)

Tim Dorr
  • 4,861
  • 2
  • 21
  • 24