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

Has anyone tried using the OAuth key and secret for Twitter in an app? I'd be interesting in seeing the code if someone has. I believe this would allow tweets to be seen as "via A Cool Titanium App".

— asked March 17th 2010 by Troy Taylor
  • oauth
  • twitter

7 Answers

  • BirdHouse: Twitter OAuth for Android & iPhone

    To anyone would like to use Twitter or is having trouble using a Twitter script,

    Cross-Platform Support & Up-to-Date: BirdHouse has been tested on Android with Linux and Mac as well as on iPhone, both using the latest Titanium Mobile SDK (1.6.2). It has been tested by others and is being maintained to fix any issues.

    Go here for the code and go here for the test app.

    About: The script can send tweets, retrieve tweets, authenticate, "deauthenticate", and send custom API calls to Twitter. For sending tweets, a custom UI popup appears. It is designed to work similar to Titanium's Facebook module.

    David Riccitelli's oauth-adapter doesn't work on Android, but some have forked it to work, such as Ketan Majmudar (go here for his code), I have tried other OAuth scripts as well, but I have been more successful with BirdHouse.

    — answered April 19th 2011 by Joe iEntry
    1 Comment
    • OH my GOD! I love you man! Joe you are my hero! This is the best script I have seen! So simple, so well commented! So easy to set up!
      BirdHouse is the simplest way to go David Riccitelli's is just obtrusive and difficult to get going right away! Birdhouse you can simply plug in and launch!! Awesome!

      — commented June 1st 2011 by Ian Tearle
  • My app Tweeku is a 1.0 app that uses Twitter OAuth (it's in the App Store). I still have a clumsy requirement that the user manually key the pin # twitter returns, which I hope to workaround with some improved access to webView properties in upcoming Titanium release (hint, hint).

    Otherwise, it's a pretty smooth experience. I would be willing to share my code. It's based on the Javascript OAuth library that's publicly available.


    — answered March 17th 2010 by Greg Pierce
  • When you say the 'pin' - are you talking about a loooong one? Or a short pin code?

    If it's the short one, you should really let/force the user to type this in, as this is kind of why oAuth exists, to provide greater security.

    Having your app automatically do this might not be the best thing to do.

    Love to see your code on this though :)

    by the way, if you want to get the html from a remote webView use a listener:

    eg: if your webView is called 'webwindow' :

                Ti.API.info("webview loaded e.url : "+e.url);
                Ti.API.info("webview html: "+webwindow.html);

    then you could parse out the info you're looking for ;)


    — answered March 17th 2010 by Kosso
  • I would be interested in seeing your OAuth implementation. Thanks!

    — answered March 31st 2010 by Darin Pope
  • Ok, something is broken here. Since Oauth depends on a redirect to the callback URL, things start breaking down when the redirect happens. My called back (app://Resources/file.html) url is loading, however, many things seem to fail (in iphone emulator at least) in that context. Ti….anything gives nothing. Ti.API.info() does nothing, fireEvent does nothing. If I directly load the url in the webview, those calls work, but if they're loaded from a redirect, crickets. I even tried catching the "load" event. The event gets caught, but e.url value stays persistant to the "authorize" URL I called rather than the URL that the server redirected my webview to (oauth_callback). The redirect actually happens, but the e.url value caught in the load event is not properly changing. I hope 1.3 has this fixed.

    Greg, I am using the same Javascript OAuth library you are using. Are you using the Iphone emulator? How are you getting the oauth_verifier that is sent in the redirected url that is passed in oauth_callback?


    — answered April 29th 2010 by Gabriel Cox
  • 10 lines of code with the OAuth Adapter:

    var oAuthAdapter = new OAuthAdapter(
    // load the access token for the service (if previously saved)
    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
            // save the access token
        // 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
  • I was struggling with Twitter til today.

    There is a really good answer on this post. check it out

    — answered May 16th 2011 by Rafael Cardoso
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.