i created a facebook app name bitsutopia, i wanted to invite my friends to that app using php.
i am using iframe in that app. i got this code from http://developers.facebook.com/docs/reference/fbml/request-form/ php script to show invite friends box. but it is not working. code –
<?php
// Get these from http://developers.facebook.com
$api_key = 'xxxx';
$secret = 'xxxx';
// Names and links
$app_name = "Bitsutopia";
$app_url = "https://apps.facebook.com/bitsutopia/";
$invite_href = "fb.php";
require_once 'facebook.php';
$facebook = new Facebook($api_key, $secret);
$facebook->require_frame();
$user = $facebook->require_login();
if(isset($_POST["ids"])) {
echo "<center>Thank you for inviting ".sizeof($_POST["ids"])." of your friends on <b><a href=\"http://apps.facebook.com/".$app_url."/\">".$app_name."</a></b>.<br><br>\n";
echo "<h2><a href=\"http://apps.facebook.com/".$app_url."/\">Click here to return to ".$app_name."</a>.</h2></center>";
} else {
// Retrieve array of friends who've already authorized the app.
$fql = 'SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1='.$user.') AND is_app_user = 1';
//$_friends = $facebook->api_client->fql_query($fql);
// Extract the user ID's returned in the FQL request into a new array.
$friends = array();
if (is_array($_friends) && count($_friends)) {
foreach ($_friends as $friend) {
$friends[] = $friend['uid'];
}
}
// Convert the array of friends into a comma-delimeted string.
$friends = implode(',', $friends);
// Prepare the invitation text that all invited users will receive.
$content =
"<fb:name uid=\"".$user."\" firstnameonly=\"true\" shownetwork=\"false\"/> has started using <a href=\"http://apps.facebook.com/".$app_url."/\">".$app_name."</a> and thought it's so cool even you should try it out!\n".
"<fb:req-choice url=\"".$facebook->get_add_url()."\" label=\"Put ".$app_name." on your profile\"/>";
?>
<fb:serverfbml style="width: 650px;">
<script type="text/fbml">
<fb:fbml>
<fb:request-form
action="<?php echo $invite_href; ?>"
method="post"
type="<?php echo $app_name; ?>"
content="<?php echo htmlentities($content,ENT_COMPAT,'UTF-8'); ?>">
<fb:multi-friend-selector
actiontext="Here are your friends who don't have <?php echo $app_name; ?> yet. Invite whoever you want -it's free!"
exclude_ids="<?php echo $friends; ?>" />
</fb:request-form>
</fb:fbml>
</script>
</fb:serverfbml>
<?php
}
?>
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
<script type="text/javascript">
FB_RequireFeatures(
["CanvasUtil"],
function(){
FB.XdComm.Server.init('/xd_receiver.html');
FB.CanvasClient.startTimerToSizeToContent();
}
);
</script>
<script type="text/javascript">
FB_RequireFeatures(["XFBML"], function(){ FB.Facebook.init("Your Facebook API Key", "/xd_receiver.html"); });
</script>
the invite box is not appearing in the app page. anything wrong in this one?
fmbl does not work with iframe apps with my experiance
I use either
or with the java sdk
this one i like better 🙂 but its harder to get your head around
without the redirect if you are not worried about who they invited
sorry about the horrible copy and paste coding.. was rushing