Accessing Tweets Using Flex.

This tutorial  will explain how you can access tweets of a user using his/her twitter username .

Things you need

1) Flex sdk to build the file

2) Notepad

3)Twitter account to access tweets :p

There are two part you need a php file and a flex counter-part
Why do i need php?? hold on guys!!!!!.

If i try to access tweets directly from flex it throws an security error which is why i call a php to retrieve all the data and send it back to flex.In the flex side i’m just populating the data into a datagrid. you can use better ui once u get the basic.
This is the logic flow
1-> enter the twitter user id
2-> using the user id i pass it to the php code using httpservice of flex. in the
php with the help of twitter api get the rss feeds for that user.
(the php code for that is show below .i’ve put the file in my html directory and the file name is tweet.php)


$username = $_GET[‘user_id’];
$twitter_feed = “”.$username.”.rss”;
$rawfeed = @file_get_contents($twitter_feed);
print $rawfeed;

3-> As you can see i’m getting the userid and constructing the api to get the rss
feed of that user
4->Once done i pass the rss to the flex .

5->Once inside flex its straight forward i just need to populate the datagrid with
the values.

Below is the FLEX code.

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”” layout=”absolute” width=”100%” height=”100%” creationComplete=”init()”>
<mx:HTTPService id=”rssParse”
result=”r_Handler(event)” fault=”error(event)”>


<!– Now lets set up the controllers for this application –>
import mx.managers.PopUpManager;
import mx.collections.ArrayCollection;
import mx.controls.Alert;

private var f_Array:ArrayCollection;

private function init():void{

private function onGetUser():void{
var obj:Object = new Object();
obj[‘user_id’] = userId.text;

private function r_Handler(event:ResultEvent):void
if(event.result.rss == null){“User id may be wrong”);
f_Array = as ArrayCollection;

private function f_Handler(event:FaultEvent):void
private function error(error:FaultEvent):void{“oppoapsaospaospo”);

<mx:VBox width=”100%” height=”100%”>
<mx:Label text=”Enter Twitter User Id”/>
<mx:TextInput id=”userId”/>
<mx:Button label=”Go” click=”onGetUser()”/>

<mx:DataGrid x=”0″ y=”56″ width=”100%” height=”100%” dataProvider=”{f_Array}”>

<mx:DataGridColumn headerText=”Title” dataField=”title”/>
<mx:DataGridColumn headerText=”Date” dataField=”pubDate”/>


Please leave a comment or a query i’ll be happy to help you.