Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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.

— asked April 26th 2010 by Altaf Sayani
  • oauth
  • twitter
0 Comments

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);
    }
    
    — answered July 2nd 2010 by David Riccitelli
    permalink
    2 Comments
    • I am getting exception using above code as

       message = "Can't find variable: PinFinder";
      

      — commented August 9th 2012 by Umaid Saleem
    • I am having error

      [ERROR] Error Domain=com.google.GDataXML Code=-1 "The operation couldn’t be completed. (com.google.GDataXML error -1.)". in -[TiDOMDocumentProxy parseString:] (TiDOMDocumentProxy.m:57)
      [WARN] Exception in event callback. {
      line = 231;
      message = "Error Domain=com.google.GDataXML Code=-1 \"The operation couldn\U2019t be completed. (com.google.GDataXML error -1.)\". in -[TiDOMDocumentProxy parseString:] (TiDOMDocumentProxy.m:57)";
      sourceId = 166403200;
      sourceURL = "file://localhost/Users/catalists/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/A190F811-B61B-4755-A4D0-E97CDD48A47A/BirdHouse.app/oauth_adapter.js";
      }

      — commented August 13th 2012 by Umaid Saleem
  • 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.

    — answered April 26th 2010 by Greg Pierce
    permalink
    2 Comments
    • can you send me sample project about this…at jnj.idr@gmail.com

      — commented August 21st 2012 by Jayesh Joshi
    • Hi, could you send sample project about this to raju.aaleti@yahoo.com

      — commented August 29th 2012 by Raj A
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.