Reading news feed into the virtual world

Inside an online social community, users want to know what their friends are doing. News feed is one of the sources that friends can share what they did recently or what they think is interesting. The news feed is displayed on the front page of the Facebook account by default. We can fetch the news feed from the API and display them inside the Flash virtual world. We will further filter the news feed to only display friends' news feed which is related to the Flash virtual world application.

Reading news feed into the virtual world

In order to fetch the news feed from the API, we need to grant another permission from the user.

_fb.grantExtendedPermission("read_stream");

We will use the GetStream class to fetch the news feed stream. There is a parameter to filter the fetching result. We can pass the app_ApplicationID to filter the result with the specific application only. Here my application ID of the Flash virtual world is 10910600246265, and the filter parameter is app_10910600246265. You should have another application ID when creating your own Facebook application.

private function readNewsFeed():void {
var fbcall:GetStream = new GetStream(FacebookClient.fb.uid,null, null,null,30,'app_109106002462653'),
fbcall.addEventListener(FacebookEvent.COMPLETE, onGotNewsFeed);
FacebookClient.fb.post(fbcall);
}

The result data is in GetStreamData structure. We can get the news feed content from stories and related users information from profiles. According to our newspaper layout, we will display the actor's profile picture of the news feed and also the dates and content from the latest two news feed. Then we display the headline of the third news feed.

private function onGotNewsFeed(e:FacebookEvent):void {
e.target.removeEventListener(FacebookEvent.COMPLETE, onGotNewsFeed);
var i:int = 1;
if (e.success){
var data:Array = (e.data as GetStreamData).stories. toArray();
var profiles = (e.data as GetStreamData).profiles;
for each(var streamData:StreamData in data) {
var profile = profiles.findItemByProperty('id',stream Data.actor_id);
if (i <= 2){
this['txtName'+i].text = profile.name;
this['txtDate'+i].text = streamData.updated_ time;
this['txtContent'+i].text = streamData. message;
if (profile.pic_square != undefined && profile.pic_square != '')
{
this['_loader'+i] = new Loader();
//this['_loader'+i].contentLoaderInfo.addEventListener(Event. COMPLETE, profilePicLoaded);
this['_loader'+i].load(new URLRequest(profile.pic_square));
this['profilePic'+i].addChild(this['_loader'+i]);
}
}else{
this['txtContent3'].text = profile.name + " : " + streamData.message;
}
i++;
}
}
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.160.156