I know this is pretty damn simple, but in case you’re in a hurry here’s a quick example of using bit.ly in as3 i whipped up. This is really just the basics. I will likely expand on it, but you can get the gist.
- Download as3corelib : http://code.google.com/p/as3corelib/
- Sign up with bit.ly : http://bit.ly/account/register?rd=/
- That’s pretty much it….
import com.adobe.serialization.json.JSON
var login:String = "put your bit.ly login here";
var api:String = "put your bit.ly api key here. It's on your account details page";
var url:String = escape("the url you want to shorten");
var bitly:String = "http://api.bit.ly/shorten?version=2.0.1&longUrl="+url+"&login="+login+"&apiKey=" + api;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, completeHandler);
loader.load(new URLRequest(bitly));
function completeHandler(ev:Event):void
{
var bitlyObj:Object = JSON.decode(ev.target.data);
var o:Object = bitlyObj.results[url];
if(bitlyObj.statusCode == "OK")
{
trace("Success! Short URL is : " + bitlyObj.results[url].shortUrl);
}
}
That’s pretty much it. I didn’t write my error handling yet, but it’s pretty simple. Just trace out ev.target.data to see the JSON structure in case you need more details ^^
Hope it helps
*Updated to add the escape to the URL.