Created
May 19, 2011 01:58
-
-
Save kosso/980017 to your computer and use it in GitHub Desktop.
Workaround for Twitter OAuth in Ti
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var url_string = null; | |
function findUrl(s){ | |
// Parses the callback url including oauth_token and oauth_verifier from the webView error message. (The url occurs twice in the long message) | |
var hlink = /(ht|f)tp:\/\/([^ \,\;\:\!\)\(\"\'\<\>\f\n\r\t\v])+/g; | |
return (s.replace (hlink, function ($0,$1,$2) { s = $0.substring(0,$0.length); | |
while (s.length>0 && s.charAt(s.length-1)=='.') | |
s=s.substring(0,s.length-1); | |
//var the_link = '<a style="color:#546F8A;font-weight:bold;text-decoration:none;" href="javascript:web(\''+s+'\')">'+s+'</a>'; | |
var the_url = s; | |
url_string = the_url; | |
return the_url; | |
} | |
) | |
); | |
} | |
// .... blah blah .. do stuff like open windows with webviews etc.. | |
// I've left out all the actual OAuth message signing stuff.. | |
webView.addEventListener('error',function(e){ | |
// After authenticating, Twitter will try to close the window. | |
// Obviously, since this a webView, this will break.. so... | |
// look for the failed call to the non-existent callBack URL in the error message. | |
findUrl(e.message); | |
if(url_string!=null){ | |
Ti.API.info('OK. The webview could not get to : '+url_string); | |
// This is because we register a non existent url as the callback url on Twitter. | |
Ti.API.info('This is a good error ;) .. now parse it'); | |
var uParams = url_string.split('?')[1].split('&'); | |
Ti.API.info(uParams); | |
var the_oauth_token = uParams[0].split('=')[1]; | |
Ti.API.info('the_oauth_token : '+the_oauth_token); | |
// this is the one we want to send back to get an access token.. | |
var the_oauth_verifier = uParams[1].split('=')[1]; | |
Ti.API.info('the_oauth_verifier : '+the_oauth_verifier); | |
pin = the_oauth_verifier; | |
// next, use the oauth_token and oauth_verifier to get the access token and store it. | |
// ... | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment