Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook canvas app - invite friends

I'm writing a Facebook iframe/canvas app and would like to give users the ability to invite friends to install this app. Currently I am using Facebook's PHP-SDK for logging in the users and all interaction with Facebook. The only things I can find about implementing the invite friends dialog either relate to FBML, which has bee deprecated; or the requests dialog: https://developers.facebook.com/docs/reference/dialogs/requests/ . The latter seems to require the use of Facebook's Javascript SDK, which has its own methods for login.

Is the JS SDK my only option, and if so, how can I use this without forcing my users to have to login again?

like image 813
Chrisj Avatar asked Oct 10 '22 14:10

Chrisj


1 Answers

first approach:

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/
            }

Second Approach:

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

third approach(using 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"]);
     }
?>
like image 154
whatf Avatar answered Oct 31 '22 02:10

whatf