Twitter oAuth?
I was wondering if there any API or way out to integrate twitter oAuth in Titanium Mobile or if anyone implemented it in their app can share code?
As announced by Twitter their basic authentication method (currently using in KitchenSink app) is going to be depreciated by June 30 so I think Appcelerator team must introduce api for integrating oAuth in next release.
2 Answers
-
Accepted Answer
10 lines of code with the OAuth Adapter:
var oAuthAdapter = new OAuthAdapter( '<your-consumer-secret>', '<your-consumer-key>', 'HMAC-SHA1'); // load the access token for the service (if previously saved) oAuthAdapter.loadAccessToken('twitter'); oAuthAdapter.send('https://api.twitter.com/1/statuses/update.json', [['status', 'hey @ziodave, I successfully tested the #oauth adapter with #twitter and @appcelerator #titanium!']], 'Twitter', 'Published.', 'Not published.'); // if the client is not authorized, ask for authorization. the previous tweet will be sent automatically after authorization if (oAuthAdapter.isAuthorized() == false) { // this function will be called as soon as the application is authorized var receivePin = function() { // get the access token with the provided pin/oauth_verifier oAuthAdapter.getAccessToken('http://twitter.com/oauth/access_token'); // save the access token oAuthAdapter.saveAccessToken('twitter'); }; // show the authorization UI and call back the receive PIN function oAuthAdapter.showAuthorizeUI('http://twitter.com/oauth/authorize?oauth_token=' + oAuthAdapter.getRequestToken('http://twitter.com/oauth/request_token', [['oauth_callback', 'oob']]), receivePin, PinFinder.twitter); }
-
I have an App in the store that has implemented Twitter OAuth. It's not that tough to do if you understand the OAuth process.
I used the Javascript OAuth libraries from the OAuth sample page: http://oauth.net/code/
Basic process is:
1) requestToken from Twitter
2) open a webView to the Twitter auth page with the token
3) add a "load" event listener to the webView that checks the webView html for the oauthPin div to appear.
4) when the user has authed, and the load event finds the pin# in the html of the webView, take that pin, and request token/secret from Twitter and store those for your user.Hope that helps…greg.