Facebook邀请没有加载iframe的朋友框

时间:2011-09-06 06:55:05

标签: php facebook

我创建了一个facebook app name bitsutopia,我想用php邀请我的朋友到那个应用程序。 我在那个应用程序中使用iframe。我从http://developers.facebook.com/docs/reference/fbml/request-form/ php脚本中获取此代码以显示邀请朋友框。但它不起作用。代码 -

<?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>

邀请框未显示在应用页面中。这个有什么问题吗?

1 个答案:

答案 0 :(得分:0)

根据我的经验,fmbl无法使用iframe应用

  

我们正在弃用FBML。如果你正在建立一个新的   在Facebook.com上申请,请使用   HTML,JavaScript和CSS。您可以使用我们的JavaScript SDK和Social   插件可嵌入许多相同的社交功能   FBML。虽然仍有功能尚未移植   但是,我们不再向FBML添加新功能。   引自http://developers.facebook.com/docs/reference/fbml/

我使用

 $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>");

或使用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>

这个我更喜欢:)但是更难以理解

<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>
如果你不担心他们邀请了谁,那么

没有重定向

对于可怕的复制和粘贴编码感到抱歉..正在匆忙