- Loading...
- No images or files uploaded yet.
|
|
SWX Twitter APIIntroduction
SWX is the easiest way to build Flash applications that use Twitter.
SWX stands for SWF Data Exchange Format. It’s a new, native, data format for Flash that uses simple SWF files to store and exchange data.
How simple is it to get Twitter data into Flash using SWX? Here\47s a quick example:
Test your FLA and look in the SWX Data Analyzer to see the last 20 public timeline updates as they load into your Flash application.
To display the updates in Flash, trace out the value of loader.result.
That's all you need to start working with SWX and Twitter! No API 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.
The SWX gateway you'e hitting is the public SWX gateway on swxformat.org. You are welcome to use this gateway to build your applications or you can host your own gateway on your own server. See swxformat.org for more infomration on how to do that.
SWX is open source and currently in Beta. You can download the latest Beta from the SWX download page.
The Easiest Way to Play Around with the SWX Twitter API
The SWX Service Explorer allows you to test out API methods without having to build a Flash front end. Concepts
Consuming a SWX service
Consuming a SWX service from Flash is very simple. Here\47s an example that shows you how to get the last public status update from my friends and display the update text using the custom getNumFriendsUpdates method in the SWX Twitter API.
In this example, we are using the SWX class to give us an abstract way of working with SWX that doesn\47t require us to work manually with movie clips. This is known as the SWX Full API and it is the recommended way to use SWX.
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); }
The data is returned in native Flash format (as an array of Flash objects, strings, etc.) and doesn't require any deserialization. (That's the key thing about SWX: You're loading in a SWF that contains your data. This is compiled Flash bytecode -- as native as a data format can get!) SWX Data AnalyzerSWX Data Analyzer is a Flex 2 application that talks to SWX data SWFs that are in debug mode (dataHolder.debug = true). It does this via LocalConnection so you can debug remote files as well as local ones. PHP Service BrowserSWX Service Explorer is a Flex 2 application that lets you test out your server-side services without having to build a Flash front-end. Other gateways and Flash Remoting, JSON, etc. support.One of the cool things about SWX is that it includes another open source project called Amfphp (Flash Remoting for PHP) and SWX services are compatible with Amfphp services. This means that, thanks to Amfphp, you can write a service (like the Twitter service) once and then consume it either through SWX by hitting the SWX gateway, or AMF (Flash Remoting) by hitting the AMF gateway, or through JSON, or XML-RPC.
For example, to get my last ten friend's updates, you can hit the JSON gateway that comes with SWX by hitting the following URL: http://swxformat.org/php/json.php/Twitter.getNumFriendsUpdates/aral/1
Official Twitter API MethodsThe SWX Twitter API supports all of the official Twitter methods. Since these are documented in the official Twitter API documentation, this section will only list the method names (as some of them differ slightly) and their signatures.
In the list below, the official Twitter API method name is listed first, followed by the PHP service method name as it exists in the SWX Twitter API. Parameters in [square brackets] are optional.
You can interactively test these methods using the SWX Service Explorer: http://swxformat.org/php/explorer/
SWX gateway: http://swxformat.org/php/swx.php AMF gateway: http://swxformat.org/php/amf.php JSON gateway: http://swxformat.org/php/json.php Status methodspublic_timelinepublicTimeline([since_id]) friends_timelinefriendsTimeline(user, pass, id, [since])user_timelineuserTimeline(user, pass, id, [count], [since]) show_statusshowStatus(id)updateupdate(update, user, pass)repliesreplies(user, pass, [page])destroydestroy(id, user, pass)
User methodsfriendsfriends(username)followersfollowers(user, pass)featuredfeatured(user, pass)show (user)showUser(id, user, pass)
Direct Message Methodsdirect_messagesdirectMessages(user, pass, [since])sentsentDirectMessages(user, pass, [page], [since], [since_id])newnewDirectMessage(recipient, message, user, pass) destroydestroyDirectMessage(id, user, pass)
Friendship MethodscreatefriendshipCreate(id, user, pass)destroyfriendshipDestroy(id, user, pass) verify_credentialsverifyCredentials(user, pass) end_sessionendSession(user, pass)
Custom SWX Twitter API MethodsThe following methods are unique to the SWX Twitter API and are not part of the official Twitter API. They may stop working at any time if Twitter is updated. Custom Status MethodsgetNumPublicTimelineUpdates ([n],[since])
getPublicUpdates (userName, [n], [since])Alias for getNumPublicTimelineUpdates. getNumFriendsUpdates (userName, [n], [since])
Custom Friendship MethodsfriendsNoAuth (user)
followersWhoAreNotFriends (yourUserName, yourPassWord)Returns a list of people who have added you as a friend but whom you have not added as a friend. (Some social networks call these "fans"; Twitter used to call them followers).
getFans (yourUserName, yourPassWord)Alias for followersWhoAreNotFriends.notifications (state, friendId, friendUserName, yourUserName, yourPassWord)
followFriend (friendId, friendUserName, yourUserName, yourPassWord)
leaveFriend (friendId, friendUserName, yourUserName, yourPassWord)
Deprecated MethodsThese are methods that are deprecated as of the upcoming Beta 1.4 release of SWX. Please do not rely on these methods as they may not be in the final release version of SWX (or even in later betas).
addFriend (friendId, friendUserName, yourUserName, yourPassWord)Use the new friendshipCreate() method instead.
removeFriend (friendId, friendUserName, yourUserName, yourPassWord)Use the new friendshipDestroy() method instead.
Getting HelpJoin the SWX mailing list.
Otherwise, please feel free to email me directly at aral at aralbalkan dot com and/or leave a comment on the SWX blog (http://swxformat.org). AuthorsThis document is authored and maintained by Aral Balkan, the author of SWX. |
Comments (1)
Armando Leopoldo Keller said
at 3:50 pm on Sep 28, 2008
i got this error:
details: /home/swxforma/public_html/php/core/shared/app/BasicActions.php
level: User Error
description: The class {Amf3Broker} could not be found under the class path {/home/swxforma/public_html/php/services/amfphp/Amf3Broker.php}
line: 33
code: AMFPHP_FILE_NOT_FOUND
You don't have permission to comment on this page.