Avg. Rating 4.0

Problem

I want a quick and dirty way to display a Twitter feed in my application.

Solution

Write a small library to load a feed and display it.

Detailed explanation

It seems Twitter is the latest craze to communicate and the Twitter API works extremely well with Flex.  However, to get started it may seem daunting so here's a simple way to load and display a Twitter feed.

 

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="{feedLoader.send()}">

<mx:Script>

<![CDATA[

import mx.controls.Alert;

import mx.rpc.events.FaultEvent;

import mx.rpc.events.ResultEvent;

private function onRes(event:ResultEvent):void

{

_tweets = new XMLList(event.result.status);

}

private function onFault(event:FaultEvent):void

{

Alert.show("Unable to load feed!","Error");

}

[Bindable]private var _tweets:XMLList;

]]>

</mx:Script>

<mx:HTTPService id="feedLoader" url="http://twitter.com/status/user_timeline/nathanpdaniel" resultFormat="e4x" result="onRes(event)" fault="onFault(event)" />

<mx:VBox width="400">

<mx:Repeater id="repeat" dataProvider="{_tweets}" width="400">

<mx:Text text="{repeat.currentItem.text}" width="100%" />

</mx:Repeater>

</mx:VBox>

</mx:Application>

 

This is as basic and easy as it gets.  My twitter username is nathanpdaniel, you can change the url to load any user's public timeline by simply changing "nathanpdaniel" to anything you like.

 

Report abuse

Related recipes