The topic of this post is quite self explanatory. Let’s say you have a super extra great application on Facebook and next thing you wanna do is to stimulate the traffic, let people know that your app exists. The ideal situation is to get rid of this job and let users to do it for you. All you got to do is to implement funcionality of inviting users friends and there you go. A virus metaphor is really good to describe what will happen next. We will use new Facebook Graph API. Let’s do it.
I assume that you know how to create facebook application and I will not cover it here. There are many tutorials on the web so I don’t think there is need to duplicate it. Go grab the source files and take a look at the main actionscript file. Just few lines of code to point out:
Call invitation method:
private function inviteFriends():void
{
var dat:Object = new Object();
dat.message = "Let's invite friends for our Super Extra Max Facebook App, more info go to http://blog.ukasz.com";
dat.title = 'Super Extra Max Facebook App';
// filtering for non app users only
dat.filters = ['app_non_users'];
//You can use these two options for diasplaying friends invitation window 'iframe' 'popup'
Facebook.ui('apprequests', dat, onUICallback, 'popup');
}
First we have to create Object to store all data we want to pass to Facebook:
- message – text you want to appear during invitation
- title – title of invitation
- filters – we don’t want to invite users that are already using app, so we’re using this filter
Invitation handler method:
private function onUICallback(result:Object):void{
if(result == null){
trace('User closed the pop up window without inviting any friends');
return
}
var invitedUsers:Array = new Array();
invitedUsers = result.request_ids as Array;
trace('You Have Invited ', invitedUsers.length,' friends');
//Simple if else if you want user to invite certain amount of friends
if(invitedUsers.length > 1){
trace('GREAT, USER IS GENERATING TRAFFIC');
}else{
trace('No Good, User invited only one friend.');
}
}
Now we’re getting fcbk callback which is invited friends list, we treat it as an array and check how many friends were invited. You can place this method at some part of your app, and for example let users play/try again only if they invite at least five friends. Nice isn’t it?
Remember that this will NOT work locally. Source files - facebook friends invitation (708)

