Using Flex and PHP it is possible to integrate Twitter RSS feeds into a Flex web page. Twitters cross domain policy (which is used by Flash) does not allow external resources to access feeds. Using PHP as a medium to the data, Flex can access the feed and display all contents. This technique can be used to access any xml data that Flex may not have access to.

Let’s start by creating an HTTPService:

	resultFormat="e4x" />

Next we will create the function to process the results:

import mx.collections.ArrayCollection;

private var _rssResults:ArrayCollection;

// Define and use atom namespace.
private namespace atom = “”;
use namespace atom;

private function processResult(event:ResultEvent):void
var xmlList:XMLList = as XMLList;
for each(var item:XML in xmlList){
var myDate:String = item.pubDate;
myDate = myDate.slice(0,22);
_rssResults.addItem({title: item.title, date: myDate});

private function init():void
_rssResults = new ArrayCollection();

Now lets add the mxml to display the content:

<mx:VBox width="400" height="600" horizontalAlign="center">	
	<mx:Label styleName="subTitleText" text="Twitter Feed:" fontWeight="bold" fontSize="16"/>
	<mx:VBox height="500" width="400" verticalScrollPolicy="auto" horizontalScrollPolicy="off" horizontalAlign="center">
		<mx:Repeater id="twitter" dataProvider="{_rssResults}">
			<mx:Text textAlign="center" width="300" text="{}"/>
			<mx:Text textAlign="center" width="300" text="{twitter.currentItem.title}"/>

After testing the application locally everything works great! But wait… what about the PHP code? Well first export a release build of the application and upload it to a web server for testing.

Here is the error that you should recieve:
[RPC Fault faultString=”Security error accessing url” faultCode=”Channel.Security.Error” faultDetail=”Destination: DefaultHTTP”]

To get around this let’s create a php file that collects the twitter data:

$twitter_feed = '';
$rawfeed = @file_get_contents($twitter_feed);
print $rawfeed;

Now we need to update our HTTPService request to pull from the new php file:

	resultFormat="e4x" />

Now everything works great!

Check out this link to view a functional example:

And the source files:

Please leave a comment if you have any questions, comments, or suggestions. Thanks!

11 thoughts on “FlexFeed: Twitter RSS Feeds in Flex

  1. You can use any server side language as a medium to access Twitter. I used php since it is the one that I am most familiar with. I would be interested in seeing what the jsp looks like if anyone is willing to post it here. Thanks!

  2. What’s the purpose of the atom namespace? You don’t seem to define or reference any name in or from it.

  3. Here is info from Adobe:

    “When working with XML, ensure that you open any namespaces that you want to use. The namespace for the Flickr RSS feed is You must define a namespace and set it to this unique URL and then include the use statement for that namespace. Otherwise, you do not have access to the contents of the loaded XML document.”

    and info on Nampspace:

    Declaring a name space in Flex will affect all subsequent calls to xml from there on out.

  4. The PHP does not seem to consistently retrieve the data via this script (PHP). I can only occasionally receive the data into flex. any ideas as to why this is?

  5. I discovered the issue was with the PHP settings on my server. Never mind the previous posts. Thanks again for the great tutorial!

  6. Hey thanks for this, I was making calls directly from flash, and it worked fine locally, then I uploaded to my server, and I got nothing. Hit google and found this, solved my problem within 5 mins. Thanks!

  7. Yup. You can use htmlText rather than text when setting the variable. It doesn’t look like twitter is returning the a href tags though. That means that you would need to parse the text and use a regular expression to add the link tags into the string before setting the htmlText.

    Sample RegExp:
    var regEx:RegExp = new RegExp(‘[a-zA-Z]+://([.]?[a-zA-Z0-9?=&%#_/-])*’, ‘ig’);
    _dynamicText.htmlText = string.replace(regEx, “<a href=\”$&\”><u>$&</u></a>”);

  8. Hi, I got this error when run it on firefox

    [RPC Fault faultString=”Error #1088: The markup in the document following the root element must be well-formed.” faultCode=”Client.CouldNotDecode” faultDetail=”null”]
    at mx.rpc.http::HTTPService/
    at mx.rpc::AbstractInvoker/
    at mx.rpc::Responder/result()
    at mx.rpc::AsyncRequest/acknowledge()
    at DirectHTTPMessageResponder/completeHandler()

Comments are closed.