SWX Twitter API

Page history last edited by FreeAtNet 11 mos ago

Introduction

 

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:

 

  • Open the SWX Data Analyzer: http://swxformat.org/php/analyzer/
  • In Flash, create a new FLA and in that, 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");

 

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 Analyzer 

SWX 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 Browser

SWX 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 Methods

The 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 methods 

public_timeline

publicTimeline([since_id])

friends_timeline

friendsTimeline(user, pass, id, [since])

user_timeline

userTimeline(user, pass, id, [count], [since])

show_status

showStatus(id)

update

update(update, user, pass)

replies

replies(user, pass, [page])

destroy

destroy(id, user, pass)

 

User methods 

friends

friends(username)

followers

followers(user, pass)

featured 

featured(user, pass)

show (user)

showUser(id, user, pass)

 

 

Direct Message Methods 

direct_messages

directMessages(user, pass, [since])

sent

sentDirectMessages(user, pass, [page], [since], [since_id])

new

newDirectMessage(recipient, message, user, pass) 

destroy

destroyDirectMessage(id, user, pass)

 

Friendship Methods 

create

friendshipCreate(id, user, pass) 

destroy

friendshipDestroy(id, user, pass) 

verify_credentials

verifyCredentials(user, pass)

end_session

endSession(user, pass)

 

Custom SWX Twitter API Methods

The 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 Methods

getNumPublicTimelineUpdates ([n],[since])

  • n Number of updates to get
  • since Narrows the returned results to just those statuses created after the specified HTTP-formatted date.

getPublicUpdates (userName, [n], [since])

Alias for getNumPublicTimelineUpdates. 

getNumFriendsUpdates (userName, [n], [since])

  • userName Username of the friend to get updates for
  • n Number of updates to get
  • since Narrows the returned results to just those statuses created after the specified HTTP-formatted date.

 

Custom Friendship Methods

friendsNoAuth (user)

  • user Username of the friend whose friends list you want to receive.

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).

  • yourUserName Your username (for authentication)
  • yourPassWord Your password (for authentication)

getFans (yourUserName, yourPassWord)

Alias for followersWhoAreNotFriends.

notifications (state, friendId, friendUserName, yourUserName, yourPassWord)

  • state True/False (true = on, false = off)
  • friendId ID of the user to modify notifications setting for
  • friendUserName Username of the user to modify notifications setting for (yes, you need to use both the id and the username)
  • yourUserName Your username (for authentication)
  • yourPassWord Your password (for authentication)

followFriend (friendId, friendUserName, yourUserName, yourPassWord)

  • friendId ID of the user to add as a friend
  • friendUserName Username of the user to add as a friend (yes you need to use both)
  • yourUserName Your username (for authentication)
  • yourPassWord Your password (for authentication)

leaveFriend (friendId, friendUserName, yourUserName, yourPassWord)

  • friendId ID of the user to add as a friend
  • friendUserName Username of the user to add as a friend (yes you need to use both)
  • yourUserName Your username (for authentication)
  • yourPassWord Your password (for authentication)

Deprecated Methods

These 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.

  • friendId ID of the user to add as a friend
  • friendUserName Username of the user to add as a friend (yes you need to use both)
  • yourUserName Your username (for authentication)
  • yourPassWord Your password (for authentication)

removeFriend (friendId, friendUserName, yourUserName, yourPassWord)

Use the new friendshipDestroy() method instead.

  • friendId ID of the user to add as a friend
  • friendUserName Username of the user to add as a friend (yes you need to use both)
  • yourUserName Your username (for authentication)
  • yourPassWord Your password (for authentication)

 

Getting Help

Join 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).

 

Authors

This document is authored and maintained by Aral Balkan, the author of SWX

Comments (1)

profile picture

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.