The new SWX Twitter API (and how to build your first Flash Twitter mashup in four lines of code!)
Twitter released an update to the official Twitter API this month and I've updated the SWX Twitter API so that it now has all the latest official Twitter API methods as well as some new custom ones.
Try it out!
You can try out the SWX Twitter API methods online right this moment by using the SWX Service Explorer.
If you want to develop Flash (and Flash Lite) applications that use data from Twitter, you can get started without installing anything at all by using the public SWX gateway on this site. (The public SWX gateway is located at http://swxformat.org/php/swx.php).
In fact, you can create your very first Twitter mashup in just four lines of code by following these simple instructions:
- Open the SWX Data Analyzer
- In Flash, create a new FLA.
- Create a new movie clip and give it the instance name loader.
- On the frame that has the loader movie clip, add the following script:
loader.serviceClass = "Twitter"; loader.method = "getPublicUpdates"; loader.debug = true; loader.loadMovie("http://swxformat.org/php/swx.php", "GET");
That's all you need to get the latest public timeline updates from Twitter into Flash (you can see that the data is being loaded if you look in the SWX Data Analyzer).
To display the updates in Flash, trace out the value of loader.result
.
Note: The Flash IDE will give you a security sandbox warning but the application will run correctly (look in the SWX Data Analyzer or trace out the loaded data to check this.) This warning occurs because you are running the SWF in the Flash IDE. If you put the SWF file on the same domain as the SWX gateway, it will also work without requiring any further code. However, if you want to use the Public SWX gateway and deploy your Flash applications to your own server, you must either manually call System.security.allowDomain, or (the recommended way is to) use the SWX Full API, as exlained below.
Notice that you didn't need to download or install anything. That's because SWX is native! It uses SWF files to store and exchange data.
That's all you need to start working with SWX and Twitter! No API, external classes, etc. are necessary! And that little snippet of code (which, by the way, fits on to a moo card) also shows you exactly how SWX works. It loads the data in a SWF file and the data is accessible the moment it loads as native Flash objects. No deserialization necessary.
Of course, if you want to host your own SWX gateway or develop and test offline on your own machine, you can download and install SWX to your own machine. That will also allow you to create your own service classes and APIs.
Using the SWX Full API
If you don't want to work manually with movie clips (and that is understandable), you can use the SWX Full API -- a completely abstract (and recommended) way of working with SWX.
Here's how to display the text of the last status update of your friends using the SWX Full API:
import org.swxformat.*;
var swx:SWX = new SWX();
swx.gateway = "http://swxformat.org/php/swx.php";
swx.encoding = "POST";
swx.debug = true;
var callParameters:Object =
{
serviceClass: "Twitter",
method: "getNumFriendsUpdates",
args: ["aral", 1],
result: [this, resultHandler]
}
swx.call(callParameters);
function resultHandler(event:Object)
{
// Display the text property of the first result.
trace (event.result[0].text);
}
I hope you enjoy working with the SWX Twitter API (also check out the Flickr API while you're at it) and, again, please feel free to hit the public SWX gateway here on swxformat.org.
New Twitter API method reference
The newly added official Twitter API methods are listed below for your convenience. You can find (and test) the full list of methods in the SWX Service Explorer.
Status methods
- replies
- destroy
User methods
- featured (was fixed in the official API and so I've re-enabled it)
Direct message methods
- sentDirectMessages
- newDirectMessage
- destroyDirectMessage
Friendship methods
- friendshipCreate
- friendshipDestroy
- verifyCredentials
- endSession
New custom methods
Status methods
- getPublicUpdates (alias for getNumPublicTimelineUpdates)
Friendship methods
- friendsNoAuth
- followersWhoAreNotFriends
- getFans (alias for followersWhoAreNotFriends)
- notifications
Deprecated methods
The following methods are deprecated as of the upcoming Beta 1.4 release in favor of the new official API methods that replace them. Please do not rely on these methods in the future as they may be removed from the API completely later on.
- addFriend (use friendshipCreate instead)
- removeFriend (use friendshipDestroy instead)
Comments
by Mo Shahin on 2007-08-14 17:53:42
by mo on 2007-08-16 02:49:10
by Aral on 2007-08-16 10:53:06
by Rob on 2008-04-07 01:54:43
by Rob on 2008-04-07 01:43:31
by Aral on 2008-04-07 09:33:36
by The Fluff on 2008-06-29 11:16:45
by satish on 2009-05-12 18:36:21
by Vedmak on 2009-05-05 19:19:28
by The new SWX Twitter API at ting on 2009-04-13 18:28:53
by 50 Twitter Tools and Tutorials For Designers and Developers on 2009-03-03 08:42:39
by All Twitter Tools & Tutorials 4 Designers & Developers | Twitter Social Networking on 2009-05-04 01:07:57
by Dan on 2009-05-04 16:45:32
by widgetDev on 2008-12-01 18:26:21
by Ian on 2009-01-27 22:40:00
by Phil on 2009-04-13 08:25:31
by Development « iDAT 203 - Negotiated Project on 2009-04-29 10:03:43
by 50 Twitter Tools and Tutorials For Designers and Developers | ClickLogin Web Design on 2009-03-03 12:57:39
by ecreatures on 2009-03-19 17:40:53
by gingerman on 2009-04-04 23:16:45
by 50 Twitter Tools and Tutorials For Designers and Developers | Tasarım,Bilim,Müzik,Kitap,Sanat,Weblog on 2009-06-06 08:54:33
by kb on 2009-06-11 10:56:51
by 50 Công cụ Twitter hay dành cho Designers và Developers | Giải Pháp Số on 2009-03-03 03:31:03
by 50 Twitter Tools and Tutorials For Designers and Developers | The Scripts Zone on 2009-03-06 06:26:18
by Aral on 2009-03-20 16:55:15
by newStuff on 2009-05-13 03:03:28
by fabian on 2009-05-13 23:06:31
by newStuff on 2009-05-14 00:02:06
by fabian on 2009-06-03 13:48:08
by md on 2009-06-21 02:33:03
by Zadek on 2009-07-29 20:33:14
by Bob on 2009-07-29 20:28:39
by Tutorials And Tips On Building A Twitter Application | How-To | PelFusion.com on 2009-07-16 20:16:00
by JacksonPowell on 2009-09-23 18:05:18
by hemanth on 2009-09-04 12:45:38
by Nit on 2009-09-10 11:52:44
by Eq on 2009-10-13 18:52:30
by Menachem on 2009-09-09 14:26:48
by melatoninTechy on 2009-09-28 05:06:52
by JacksonPowell on 2009-09-23 17:58:35
by [Flash CS3] - twitter api - tweets in flash darstellen - Flashforum on 2009-12-18 14:54:21
by ivan on 2009-12-16 16:59:26
by Fabian Meul on 2010-01-03 00:25:09
by Rafael on 2010-01-21 16:35:46
by Oyunlar on 2010-02-20 15:24:54
by Okii on 2010-09-01 14:52:39
by Twitter: 50 herramientas y Tutos. « Otto1303 on 2011-06-27 15:25:24
by 50 Twitter Tools and Tutorials For Designers and Developer | GirlyTechStuff on 2012-08-30 02:32:29