This version works fine:
function OA(options) {
this.options = options
}
OA.prototype.start = function() {
var self = this;
var parent = self.options.ui.currentView;
var oauth = require('lib/jsOAuth-1.3.5').OAuth(self.options.oauth);
var overlay = Ti.UI.createView({
backgroundColor : 'black',
opacity : 0.3
});
parent.add(overlay);
if(
Ti.Platform.name === 'iPhone OS') {
if(self.options.ui.actind) {
parent.add(self.options.ui.actind);
self.options.ui.actind.show();
}
}
oauth.fetchRequestToken(function(url) {
var webview = Ti.UI.createWebView({
width : '100%',
height : '105%',
borderRadius : 8,
borderWidth : 3,
align : 'center',
borderColor : 'silver',
transform : Ti.UI.create2DMatrix().scale(0.92),
url : url
});
parent.add(webview);
/**/
var cron = setInterval(function() {
var url = webview.url;
var vars = url.split('?')[1].split('&');
for(var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if(pair[0] == 'oauth_verifier')
self.options.oauth.oauthVerifier = pair[1];
if(pair[0] == 'oauth_token')
self.options.oauth.oauthToken = pair[1];
}
if(self.options.oauth.oauthVerifier) {
clearInterval(cron);
parent.remove(webview);
parent.remove(overlay);
oauth.setVerifier(self.options.oauth.oauthVerifier);
oauth.fetchAccessToken(function(data) {
}, function(error) {
var secrets = {
token : oauth.getAccessToken(),
key : oauth.getAccessTokenKey(),
secret : oauth.getAccessTokenSecret()
};
if(self.options.ui.success) {
var alert = Ti.UI.createAlertDialog({
buttonNames : ['OK'],
message : self.options.ui.success,
title : 'Login'
});
alert.show();
}
if( typeof (self.options.result200) == 'function') {
self.options.result200(secrets);
}
});
}
}, 500);
}, function() {
});
// oauth.fetchAccessToken(getSomeData, failureHandler);
};
module.exports = OA;