28 Jul 2007

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:

  1. Open the SWX Data Analyzer
  2. In Flash, create a new FLA.
  3. Create a new movie clip and give it the instance name loader.
  4. 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)

Add Your Comment

Spam Protection by WP-SpamFree

The new SWX Twitter API (and how to build your first Flash Twitter mashup in four lines of code!)

  1. I’m new with SWX, But have some how good experience with flash, I came across twitter and found that there is a way to integrated with flash, I’ve tried to do the simple tutorial they have online but it didn’t work
    Can you give me some hint on how to start playing with this amazing tool

    Mo Shahin
  2. I tried the above Code, without installing anything on my machine
    1- just opened flash
    2- created movieclip loader
    3- pasted your code on the first frame
    4- run and get that error

    *** Security Sandbox Violation ***
    SecurityDomain ‘http://swxformat.org/php/swx.php?serviceClass=Twitter&method=getPublicUpdates&debug=true‘ tried to access incompatible context ‘file:///F|/Untitled-1.swf’

    Any idea?
    Please email me back as I’ve been trying to figure out how the twitter works with Flash and until now I can’t do it
    I’m new to SWX

    mo
  3. Hi Mo,

    I’ve just added a note to clarify the issue you are seeing. Here it is again:

    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.

    Aral
  4. Hi, Aral.

    When I try to get at loader.result, I always get “undefined.” This is even when the result appears in SWX Data Analyzer perfectly, and even when the Flash IDE’s variable dump in the debug menu shows it.

    I’ve tried tracing loader.result, loader.result[n], loader.result[n].whatever … everything is “undefined”

    Can you help explain what this flash novice is missing here?

    Rob
  5. Figured it out; must be a typical beginner mistake. The script has to wait a few moments to get the data back, so you have to delay or repeat (e.g. onEnterFrame) the trace or output.

    Rob
  6. Hi Rob,

    Happy to hear that you got it sorted.

    I would strongly suggest that you use the SWX ActionScript Library (called the Full API,above) for any sort of real work with SWX RPC. It handles all that for you and gives you a clean interface to work with.

    The native method is great for understanding how SWX works conceptually and for building your own libraries.

    Aral
  7. Hey

    When I use SWX, I get these errors in SWX itself:

    Location: SWX.as
    Description: 1046: Type was not found or was not a compile-time constant: MovieClip.

    Location: SWX.as
    Description: 1046: Type was not found or was not a compile-time constant: Void.

    Are there bugs in SWX? shouldn’t be Void be void?

    btw: Saw you at Multi-Mania 08, great talk!

    The Fluff
  8. I built a widget using your SWX gateway months ago and it’s been working flawlessly. I just discovered that the method friendshipCreate is returning an
    error = “This method requires a POST.” This also happens in your SWX service explorer. Any ideas on why this is happening ? thanks

    widgetDev
  9. I’m getting this error every time I attempt to use the getNumFriendsUpdates method.

    Fatal error: Cannot use object of type stdClass as array in /home/swxforma/public_html/php/services/Twitter.php on line 543

    Ian
  10. [...] How to Build Your First Flash Twitter Mash-Up in Four Lines of Code! Build a Twitter mash-up in four lines of code? That’s all you need, according to this tutorial, to get the latest public timeline updates from Twitter into Flash. [...]

    50 Công cụ Twitter hay dành cho Designers và Developers | Giải Pháp Số
  11. [...] How to Build Your First Flash Twitter Mash-Up in Four Lines of Code! Build a Twitter mash-up in quaternary lines of code? That’s every you need, according to this tutorial, to intend the stylish unstoppered timeline updates from Twitter into Flash. [...]

    50 Twitter Tools and Tutorials For Designers and Developers
  12. [...] How to Build Your First Flash Twitter Mash-Up in Four Lines of Code! Build a Twitter mash-up in four lines of code? That’s all you need, according to this tutorial, to get the latest public timeline updates from Twitter into Flash. [...]

    50 Twitter Tools and Tutorials For Designers and Developers | ClickLogin Web Design
  13. [...] How to Build Your First Flash Twitter Mash-Up in Four Lines of Code! Build a Twitter mash-up in four lines of code? That’s all you need, according to this tutorial, to get the latest public timeline updates from Twitter into Flash. [...]

    50 Twitter Tools and Tutorials For Designers and Developers | The Scripts Zone
  14. I can’t understand the loadMovie expression in the sample code proposed. To me loadMovie is a deprecated expression,I tried the code in Flash and there’s no way I can get it working…

    ecreatures
  15. Hi ecreatures,

    loadMovie is used in AS2 and AS1. We have an AS3 version that’s currently in beta. Check out the documentation here: http://swxformat.org/201

    Aral
  16. Hi widgetDev,

    I am having the same problem with ‘POST’ using the friendshipCreate method and I have my code running on a webserver, so it’s not a GET/POST Flash IDE thing.
    You will notice that it does not work on the SWX public gateway either – so I doubt it will work anywhere else.

    I have created lots of apps and sites that use ‘POST’ before and they have all worked, so I am a bit confused.

    ( like you I have tried many of the other methods and they work fine )

    Cheers

    gingerman

    gingerman
  17. Hi Aral, I am currently on the pursuit to create something similar to twittervision. I am trying to do it for a university project but my knowledge on anything more than just plain actionscript and flash is minimal. Are there any tutorials you have made or any links you know of that could point me in the right direction?

    Any help would be very much appreciated,

    Phil

    Phil
  18. [...] http://aralbalkan.com/999 « twitter-web-designer-and-developer [...]

    The new SWX Twitter API at ting
  19. [...] I don’t think it would’ve given me the right results for the end product, the link is here. After countless google searches for help with the API, I resulted to looking into the ATOM feed, [...]

    Development « iDAT 203 - Negotiated Project
  20. [...] How to Build Your First Flash Twitter Mash-Up in Four Lines of Code! Build a Twitter mash-up in quaternary lines of code? That’s every you need, according to this tutorial, to intend the stylish unstoppered timeline updates from Twitter into Flash. [...]

    All Twitter Tools & Tutorials 4 Designers & Developers | Twitter Social Networking
  21. When using the second example where you try to grab the specific Member feed from twitter, nothing is returned and in SWX analyzer it gives and error saying Value = Could not authenticate you.

    Why would this be? I could have sworn that is was functioning a week or two ago.

    Dan
  22. Здравствуйте! Ищу толковый автосерфинг(платят за просмотр сайтов). Подскажите если кому что известно.
    Я нашел толковый автосерфинг vaselisk.net.ru но етого маловато.
    Он хорош более для рекламы чем для заработка.
    Заранее благодарен.

    Vedmak
  23. hi sir,
    I m new novice to SWX. How can i create my own twitter api based on swf files that provide all the functionalty similar to twitter. please help me and suggest me if you have any tutorial url regarding this.

    satish
  24. When using the second example where you try to grab the specific Member feed from twitter, nothing is returned and in SWX analyzer it gives and error saying Value = “Could not authenticate you.”

    i am receiving the same error msg, is this due to the fact that clients can make no more than 100 calls per hour perhaps?

    newStuff
  25. Hi Aral,

    Nice work on this connection between twitter and flash! I’m still experimenting a little with the search method… In the analyzer everything goes well, i’m getting my results right. But when it comes to the part where flash needs to display these results, the whole thing fails on me. I get “undefined” on everything I’ve tried. Rob said something about a delay, maybe that you or rob can show me how to solve this issue? Thank you very much!

    Kind regards Fabian

    fabian
  26. @fabian hey,

    if you move the trace a little further down the timeline as a hack, or just add a function to the onEnterFrame it will fix your problem, i had the same problem, seems like it takes a second to initialise the connection to the online API

    newStuff
  27. @newstuff thanks, but I don’t think I’m doing this right. If you have some sample to get me on the road I will be very very happy. If I just could have some information coming back after my query…

    fabian
  28. [...] How to Build Your First Flash Twitter Mash-Up in Four Lines of Code! Build a Twitter mash-up in four lines of code? That’s all you need, according to this tutorial, to get the latest public timeline updates from Twitter into Flash. [...]

    50 Twitter Tools and Tutorials For Designers and Developers | Tasarım,Bilim,Müzik,Kitap,Sanat,Weblog
  29. a example for send a tweet would be fantastic!!! king regards, kim

    kb
  30. What is the best/easiest way to add a social bookmark link for Twitter on my Flash AS3 site. I am brushing up on my Action Scripting, PHP and Ruby on rails. Is the best approach with PHP? Do you have any sample code to share?

    Best Regards,
    M

    md
  31. [...] How to Build Your First Flash Twitter Mashup [...]

    Tutorials And Tips On Building A Twitter Application | How-To | PelFusion.com
  32. I really wish this was better explained, and most importantly—simpler.

    So discouraging, I’ll do what I always do w/ Flash now—give up.

    Bob
  33. Based on many of the comments above, it seems the instructions could be improved. This is weak point in almost all tutorials of this nature. The steps are not explained well enough, or clearly enough, and even worse, incomplete information is present. The problem is very easy to pin-point…

    Developers need help with writing, instruction, and teaching…

    I speaketh the truth: if I didn’t, 2/3 of the comments above would not be there…

    Zadek
  34. 5007: An ActionScript file must have at least one externally visible definition.
    on compiling i am getting the following error,i am using the sample code thats there is twitter page

    hemanth
  35. I have registerer to twiiter oAuth
    How can i get twitter from[MyApp] when i post from my site with this gateway?

    Menachem
  36. hi aral

    when i call this function sentDirectMessages
    it throws me error
    Error:This method requires a GET.

    how to solve that problem

    Nit
  37. Oops,

    I should have mentioned that I tested the call in the Service Explorer and it worked, so I must be typing the arguments incorrectly. ?

    JacksonPowell
  38. I am trying to use the userTimeline method in flash. How do you know your user id? I put in my user name and my password along with 3 tweets to receive as arguments, but I get back someone else’s tweets and not my own? But in the service explorer when I do the above I see mine?

    Any help is greatly (read: Enormously) appreciated.

    Jackson.

    JacksonPowell
  39. i just love Twittering compared to blogging. i was a blog addict and now i am a Twitter addict.

    melatoninTechy
  40. I’m having issues getting Data when I using a method for a specific user. When I use the general “getPublicUpdates” it works! but when I use the “userTimeline” it does not work. Here is my code:

    var myData:Array = ['username', 'password', 11552255, 5];
    //import org.swxformat.*;
    loader.serviceClass = “Twitter”;
    loader.method = “userTimeline”;
    loader.args = [myData];
    loader.debug = false;

    SWX.prepare(loader);

    loader.loadMovie(“http://xxxxxxxxx.com/twitter/php/swx.php”, “GET”);

    onEnterFrame = function(){
    if (!loader.result[0]){
    }else{
    twitter.txt001 = loader.result[0].text;
    twitter.txt002 = loader.result[1].text;
    }
    }

    Eq
  41. Hola:
    tengo una pregunta.
    tengo una pagina web hecha en flash y quiero insertar mi twitter, como lo hago?
    uso flash 8 2.0

    ivan
  42. [...] api – tweets in flash darstellen Hallo, ich hab schon viel gesurft und einiges raus gefunden. Aral Balkan The new SWX Twitter API (and how to build your first Flash Twitter mashup in four lines … Twitter API Archive – SWX: SWF Data Format Tweetr AS Library Es will aber nicht so richtig [...]

    [Flash CS3] - twitter api - tweets in flash darstellen - Flashforum
  43. Hi Aral!

    I’ve been wanting to implement Twitter into my as3 project, but it seems that something goes wrong when using the “getNumFriendsUpdates” service in the SWX Service Explorer.

    Whatever name I enter to request the updates, I always get the error: **error = “Could not authenticate you.”**

    Could you please provide me with feedback on this particular issue?

    Thank you!

    Greetings,
    Fabian Meul

    Fabian Meul
  44. man…. I REAAAAALLY NEED TO KNOW HOW I DO THAT WITH DIRECTMESSAGES JUST LIKE THIS LINK:

    http://blog.eerkmans.nl/?p=3

    please… help me!!!

    big hugs and congrats!!!

    Rafael
  45. Nice work on this connection between twitter and flash! I’m still experimenting a little with the search method

    Oyunlar
  46. thank you so much for this guide, may be this is too late already for others, but this is really helping me.

    Okii
  47. [...] How to Build Your First Flash Twitter Mash-Up in Four Lines of Code! [...]

    Twitter: 50 herramientas y Tutos. « Otto1303