Introducing TwitterAspirin: an AS3 Twitter API painkiller
A couple months ago, I started working on a Twitter component for my current project at Adobe. I went into this knowing I’d have to finally face the beast… OAuth. Just about every well-known Twitter client out there uses Basic Auth—and for a reason. It’s easy, what the user expects, and gives your app more credibility—there’s no requirement to leave to authenticate through the browser like with OAuth.
About five or six months ago, Twitter decided to enforce the transition. From then on, any application that uses the API must use OAuth in order to see “via [your app]” on tweets published with it—otherwise, it would display “via API.” Since “via” is where apps get probably 90% of their referrals, this was a big deal. Luckily for me, DestroyTwitter existed before that time and Twitter decided not to push the change on the veteran apps. Recently, however, the bad news spread that Basic Auth would be deprecated in June. This means every Twitter app must transition to the pain that is OAuth.
After developing the MAX Companion this past fall and now the more generalized version, I found myself rewriting the Twitter component each time. After a while, the Twitter API code I wrote for DestroyTwitter began to merge with the actual implementation, so it was no longer a standalone library that could easily be used by other projects. These past few months, I’ve been learning a great deal about framework architecture and design patterns. It has led me to realize I need to start fresh.
With all that being said, I’d like introduce a library I started working on two days ago. I call it TwitterAspirin. It’s an AS3 Twitter API library that eases the pain, providing developers with a very powerful tool for communicating with Twitter. Though it’s still a newborn at the moment, I see potential already. The library is built on RobotLegs and uses AS3 Signals instead of events. It’s hosted on GitHub, so the source code will always be available to the public. And, after last night’s commit, its OAuth functionality is complete. Here’s how to use it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | package { import com.destroytoday.twitteraspirin.Twitter; import flash.display.Sprite; public class Test extends Sprite { // set application consumer key and secret public var twitter:Twitter = new Twitter(consumerKey, consumerSecret); public function Test() { // add signal listeners twitter.oauth.requestTokenSignal.add(requestTokenHandler); twitter.oauth.accessTokenSignal.add(accessTokenHandler); twitter.oauth.verifyAccessTokenSignal.add(verifyAccessTokenHandler); } // click the 'Authorize' button to get the request token protected function authorizeClickHandler():void { twitter.oauth.getRequestToken(); } // upon receiving the request token, open Twitter in the browser to authorize protected function requestTokenHandler(oauth:OAuth, token:OAuthToken):void { navigateToURL(new URLRequest(oauth.getAuthorizeURL())); } // return with the provided pin and click the 'Activate' button to get the access token protected function activateClickHandler():void { twitter.oauth.getAccessToken(pin); } // upon receiving the access token, verify it protected function accessTokenHandler(oauth:OAuth, token:OAuthToken):void { oauth.verifyAccessToken(token); } // done protected function verifyAccessTokenHandler(oauth:OAuth, token:OAuthToken):void { } } } |
As you can see, it’s extremely easy to use. Not only that, it provides great flexibility. Many libraries are simple to implement, but don’t allow the developer access to certain aspects of the process. With TwitterAspirin, each method returns the loader involved with the operation, giving developers the ability to listen for errors, cancel the operation, or attain the raw API data. The library also uses loader pools to recycle instances, so you can submit a tweet and, while it’s loading, submit another—you don’t have to wait for the first operation to finish. Then, once the operation is complete, the loader is disposed and returned to the pool, which optimizes performance and memory usage.
I’m really excited to see where TwitterAspirin goes and I have nothing but great expectations. Be sure to follow along with development and fork whenever you like.

