Twitter in Flash using SWX

Twitter is everywhere and it is becoming a fast requirement for any website let alone a Flash site.  I have tried a few of the different Twitter APIs for Flash and I think SWX is the most robust.  SWX is a native data format for Flash that can be used to make Twitter and even Flickr API calls.  All you have to do is download the latest release of SWX and then get started.  You can also upload the SWX service to your own webhost and use that as your SWX gateway.  I recommend using your own SWX gateway for any project that will be making alot of SWX calls.  The public gateway is being used in the sample code below, but keep in mind that many other people are using the same gateway for their own projects.

Start by going to the Twitter SWX API page.  You will see a full list of methods you can use, but the instructions were a little tricky.  Here is some sample code to get you started.  This is AS3 and is being used with SWX 2.0 beta.  The code below gets the three latest updates from a user timeline.  The TRACE statement only calls one update from the results array.  That should give you a good start.  Here is the source for the people that want it all.

import org.swxformat.*;

var swx:SWX = new SWX();
swx.gateway = “http://www.swxformat.org/php/swx.php”;
swx.encoding = “POST”;
swx.debug = false;

var callParameters:Object =
{
serviceClass: “Twitter”,
method: “userTimeline”,
args: ["username", "password", "username", 3, null],
resultHandler: resultHandler
}

swx.call(callParameters);

function resultHandler(event:Object)
{
// Display the text property of the first result.
trace (event.result[0].text);
}