Facebook画布应用程序 - 邀请朋友

时间:2011-07-05 09:44:55

标签: facebook facebook-php-sdk facebook-javascript-sdk

我正在编写Facebook iframe / canvas应用程序,并希望用户能够邀请朋友安装此应用程序。目前我使用Facebook的PHP-SDK登录用户以及与Facebook的所有互动。我能找到的关于实现邀请朋友对话的唯一事情与FBML有关,而FBML已被弃用;或请求对话框:https://developers.facebook.com/docs/reference/dialogs/requests/。后者似乎需要使用Facebook的Javascript SDK,它有自己的登录方法。

JS SDK是我唯一的选择,如果是这样,我如何在不强迫我的用户再次登录的情况下使用它?

3 个答案:

答案 0 :(得分:3)

第一种方法:

function newInvite(){
                 var receiverUserIds = FB.ui({
                        method : 'apprequests',
                        message: 'Come on man checkout my applications.',
                 },
                 function(receiverUserIds) {
                          console.log("IDS : " + receiverUserIds.request_ids);
                        }
                 );
                 //http://developers.facebook.com/docs/reference/dialogs/requests/
            }

第二种方法:

<?php
     include_once "fbmain.php";
    if (isset($_REQUEST['ids'])){
        echo "Invitation Successfully Sent";
        echo '<pre>';
        print_r($_REQUEST);
        echo '</pre>';
        echo "<b>If you need to save these user ids then save these to database <br />then redirect user to the apps.facebook.com/yourapp url</b>";
        $string = "<script type='text/javascript'>top.location.href='{$fbconfig['appBaseUrl']}'; </script>";
        echo "Use the following javascript code to redirect user <br />";
        echo htmlentities($string, ENT_QUOTES);
    }
    else {
?>
<fb:serverFbml style="width: 500px;">
    <script type="text/fbml">
      <fb:fbml>
          <fb:request-form
                    action="<?=$fbconfig['baseUrl']?>/invite.php"
                    target="_top"
                    method="POST"
                    invite="true"
                    type="Demo Application  Learning API"
                    content="Checkout this demo application and learn iframe base facebook application development. <fb:req-choice url='<?=$fbconfig['appBaseUrl']?>' label='Accept' />"
                    >

                    <fb:multi-friend-selector
                    showborder="false"
                    actiontext="Checkout this demo application">
        </fb:request-form>
      </fb:fbml>
    </script>
  </fb:serverFbml>
<?php } ?>

第三种方法(使用PHP-SDK):

     $app_id = "YOUR_APP_ID";

     $canvas_page = "YOUR_CANVAS_PAGE_URL";

     $message = "Would you like to join me in this great app?";

     $requests_url = "http://www.facebook.com/dialog/apprequests?app_id=" 
            . $app_id . "&redirect_uri=" . urlencode($canvas_page)
            . "&message=" . $message;

     if (empty($_REQUEST["request_ids"])) {
        echo("<script> top.location.href='" . $requests_url . "'</script>");
     } else {
        echo "Request Ids: ";
        print_r($_REQUEST["request_ids"]);
     }
?>

答案 1 :(得分:1)

是 - 目前FB JS请求对话框是唯一的方法。而且您的用户无需对您的应用进行身份验证 - 事实上,他们无需对所有用户进行身份验证。我有一个jsfiddle示例,其中包含您可以查看的代码,但您需要指定的是您的应用ID。

答案 2 :(得分:0)

目前(截至v2.3),不是游戏的画布应用程序无法邀请用户。

Can non-game app use FB apprequests dialog in FB v2