I’m Twitter Search

Actionscript:
  1. [SWF(width = 400, height=600, frameRate=12)]
  2. var loader:URLLoader = new URLLoader();
  3. var req:URLRequest = new URLRequest("http://search.twitter.com/search.atom");
  4. var vars:URLVariables = new URLVariables();
  5. vars.q = "I'm";
  6. // results per page
  7. vars.rpp = "7";
  8. vars.page = 1;
  9.  
  10. req.data = vars;
  11. req.method = URLRequestMethod.GET;
  12.  
  13. loader.addEventListener(Event.COMPLETE, onLoaded);
  14. loader.load(req);
  15.  
  16. // check for updates every 30 seconds -
  17. var timer:Timer = new Timer(30000);
  18. timer.addEventListener(TimerEvent.TIMER, onTick);
  19. timer.start();
  20. function onTick(evt:TimerEvent):void{
  21.     txt.htmlText = "loading...";
  22.     loader.load(req);
  23. }
  24.  
  25. var txt:TextField = TextField(addChild(new TextField()));
  26. txt.defaultTextFormat = new TextFormat("_sans", 12);
  27. with (txt){ x=10, y=10, width=stage.stageWidth-10;
  28. height=stage.stageHeight, multiline = true, wordWrap = true; }
  29. txt.htmlText = "loading...";
  30.                                                    
  31. function onLoaded(evt:Event):void{
  32.     var searchData:XML = new XML(loader.data);
  33.     var atom:Namespace = searchData.namespace("");
  34.     default xml namespace = atom;
  35.     var htmlText:String = "<b>Last " + vars.rpp + " '" + vars.q + "' tweets:</b><br><br>";
  36.     for each(var entry:XML in searchData.entry){
  37.         htmlText += entry.author.name.toString() + ": <br>";
  38.         htmlText += entry.title.toString() + "<br><br>";
  39.     }
  40.     txt.htmlText = htmlText;
  41. }

Was curious about the twitter search api so spent a few minutes and whipped up a quick demo - the api is simple and easy to understand...

As a test I created something that shows the last 7 tweets including the phrase I'm. A new search is done every 30 seconds... I chose the phrase I'm so that there will be different results every time a new search is done...


Below is the swf:

This movie requires Flash Player 9

I noticed that there might be some kind of caching going on as sometimes it loads the same result 2 times in a row... if you need fresh results everytime you can do this:

vars.page = int(Math.random()*100);

... not perfect but randomly chooses from 100 pages of results

This entry was posted in XML, external data and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Trackback

  1. [...] I’m Twitter Search [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*