Update: This artice is outdated, with the new Actionscript Facebook Graph API it’s much easier:
Facebook.callJS("FB.ui",{
method: 'apprequests',
message: 'Invite your friends to Appname',
to: facbookUserId
});
See the Facebook wiki for more info. You also have to include http://connect.facebook.net/en_US/all.js in the page that embeds your flash program.
outdated version:
I tried hard to figure this out and I found very little information on this topic on the Internet so this is why i wrote this article. Did you ever try to send someone an invitation to use your app? Like Farmville does with sending gifts? Then you probably stumbled upon the multi-friends-selector fbml tag. In my case i wanted to only invite one specific person via Actionscript. After much research on google i gave it up. There seems to be no way to do this from the API. But i found a good alternative which works as follows: You call a JavaScript function on your Canvas page from your Flash application. This JavaScript function pops up a dialog which includes a request from fbml tag. This dialog looks like the one in the picture on the left.
<fb:request-form action='index.php' method='POST' invite='true' type='Yor Application Name' content='Some comment here... <?php echo htmlentities("<fb:req-choice url=\"http://apps.facebook.com/musicplaylists/\" label=\"Button Caption for Accept\"") ?>' >
<fb:request-form-submit uid='xxxxx' label='%n is not using YOUR APP NAME. Klick here to invite him/her'/>
</fb:request-form>
The code above generates a Button. When the user clicks on it it opens a popup where one can enter a optional message and send the invitation. But how is this supposed to work in Actionscript? Actually it isn’t. But we can do a workaround. We can open a popup including this button. Its not the user-friendliest solution but it is a good one if you need to invite specific persons. (This person is specified by the uid attribute of the request-form-submit tag)
So we could write a JavaScript (FBJS) function to open such a dialog with the request-form in it. Unfortunately there is a problem: Because Facebook has hard restrictions for Javascript we are not able to change the value of the uid attribute of the request-form-submit tag
But there is a workaround: We can load the fbml tags per Ajax and fill them in our dialog:
<fb:js-string var="dialogInvite">
<div id="dialog_content">
<div class="dialog_loading">Loading...</div>
</div>
</fb:js-string>
<script type='text/javascript'>
<!--
function onRequestComplete(result) {
document.getElementById('dialog_content').setInnerFBML(result);
}
function do_adduser(uid) {
var ajax = new Ajax();
ajax.responseType = Ajax.FBML;
ajax.ondone = onRequestComplete;
ajax.requireLogin = true;
new Dialog(Dialog.DIALOG_POP).showMessage('Invite friends', dialogInvite,button_cancel='Cancel');
ajax.post('http://URL TO YOUR SERVER.de/invite.php?uid='+uid);
}
-->
</script>
The code of invite.php looks like this:
<fb:request-form action='index.php' method='POST' invite='true' type='Yor Application Name' content='Some comment here... <?php echo htmlentities("<fb:req-choice url=\"http://apps.facebook.com/musicplaylists/\" label=\"Button Caption for Accept\"") ?>' >
<fb:request-form-submit uid='<?php echo $_GET["uid"]?>' label='%n is not using YOUR APP NAME. Klick here to invite him/her'/>
</fb:request-form>
When you call do_adduser(13234); it would open a popup asking you to invite the user with id 13234. In Order to call this JavaScript function from within your ActionScript program you have to insert a fbjs-bridge tag before your swf tag and an empty script tag with an empty comment in it:
<fb:fbjs-bridge/> <fb:swf swfsrc="http://URL TO YOUR SERVER.de/flashapp.swf"/> <script><!-- --></script>
Now you can call do_adduser(123) from actionscript:
var lconn:LocalConnection = new LocalConnection; lconn.send(LoaderInfo(root.loaderInfo).parameters.fb_local_connection, "callFBJS", "do_adduser", [123]);
LoaderInfo(root.loaderInfo).parameters.fb_local_connection will need the fbjs-bridge working correctly.
I hope this post helped you
<fb:request-form action='index.php' method='POST' invite='true' type='Yor Application Name' content='Some comment here... <?php echo htmlentities("<fb:req-choice url="http://apps.facebook.com/musicplaylists/" label="Button Caption for Accept"") ?>' >
<fb:request-form-submit uid='xxxxx' label='%n is not using YOUR APP NAME. Klick here to invite him/her'/>
</fb:request-form>
Do you think something like this will work from iFrame not FBML canvas?
I dont’t know but it could work using XFBML
Is it possible to use fb:multi-friend-selector within that fb:request-form? When I try, I get no friends showing up.
Great article, thank you for putting all of this information together.
a fb:multi-friend-selector inside should actually work but as far as i can remember some other people where having this issue too. I have no solution to this i’m sorry.
How can i use this on iFrame canvas??
thks for ur tutorial, I’m looking to invite friends using actionScript
(call fb:multi-friend-selector from AS or FBSJ) do u have any idea how to do this ?
thks for ur time
you could open a dialog box containing the friends selector like i wrote in my article. Or just set some div container visible or so.
If you want to invite people directly from AS3: i think that is not possible
Hey Dominik,
I just discovered this blog, and really like the content! We have a blog ourselves called creative-geeks, which actually uses the same layout as you are doing. You are doing a great job with your articles.
About this article… personally I want a cleaner more easier approach, I regret to see that facebook makes it so hard for us actionscript developers
greetz
Thanks Man!!
Really really helped me, love you!!
Hi Dominik! Just wrote a small tutorial on how to invite friends to your facebook flash application using new Facebook Graph API (can be kind of sipplement of your article), source files available, anyone interested take a look http://blog.ukasz.com/facebook-invite-friends-from-flash-as3-how-to-stimulate-traffic/
Maybe you will find it usefull