Facebook Invite Friends Box with iframes is not loading
i created a facebo开发者_如何学编程ok 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
We are in the process of deprecating FBML. If you are building a new application on Facebook.com, please implement your application using HTML, JavaScript and CSS. You can use our JavaScript SDK and Social Plugins to embedded many of the same social features available in FBML. While there is still functionality that we have not ported over yet, we are no longer adding new features to FBML. as quoted from http://developers.facebook.com/docs/reference/fbml/
I use either
$requests_url = "http://www.facebook.com/dialog/apprequests?app_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page)
. "&message=" . $message;
echo("<script> top.location.href='" . $requests_url . "'</script>");
or with the java sdk
<script src="http://connect.facebook.net/tr_TR/all.js" type="text/javascript"></script>
<a href="#" onClick="FB.ui({method: 'apprequests', message: 'Here is your invite msg.', data: '', filters: ['all'], exclude_ids: ['ids,you,want,to,exclude']},
function(response) {if(response != null) {window.location='?requests='+response.request_ids;}});">Send Requests</a>
this one i like better :) but its harder to get your head around
<script src="http://connect.facebook.net/tr_TR/all.js" type="text/javascript"></script>
<a href="#" onClick="FB.ui({method: 'apprequests', message: 'Here is your invite msg.', data: '', filters: ['all'], exclude_ids: ['ids,you,want,to,exclude']}});">Send Requests</a>
without the redirect if you are not worried about who they invited
sorry about the horrible copy and paste coding.. was rushing
精彩评论