Oct 17, 2009 0
Using Bit.ly from Flash
So, I recently wanted to play around with the Bit.ly API and use it in flash. I decided it would be best to write up a nice little helper class. The usage for this is pretty simple and right now it only implements two of the API methods, shorten and expand. I’ll work on the other calls but I figured these were the most widely used.
1 2 3 4 5 6 7 8 9 10 11 12 | import com.imperez.apis.bitly.Bitly; import com.imperez.apis.bitly.events.BitlyEvent; var bitly:Bitly = new Bitly("bitly username", "user api_key"); bitly.addEventListener(BitlyEvent.SHORTEN, this._shorten); bitly.shorten("http://www.google.com/"); function _shorten(event:BitlyEvent):void { var shortURL:String = event.currentTarget.shortURL; trace(shortURL); //http://bit.ly/4BSxf } |
As you can see from the code above it’s pretty simple. Pass in your username and api key in the constructor and then listen for the BitlyEvent.SHORTEN event. Make your call along passing your long url and you are set to go. I wanted to keep this is as easy to use as possible. I also wanted to make it so you wouldn’t need to have to parse xml in order to get this information.
And that’s it. Nothing more to see but sweet, sweet code . If you’re interested I have it up on my repository located here. There are still some bug fixes and general clean up to on top of further implementation but I would say it’s a good start.