Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invite friends to Facebook using JavaScript sdk

I am new to stack overflow, how can I invite my Facebook friends to my Facebook application pro-grammatically using javascript SDK? I am a newbie regarding Facebook-Javascript. I want to send an invitation to a user's friends using my Facebook application.

like image 990
Eslam Soliman Avatar asked Dec 04 '22 07:12

Eslam Soliman


2 Answers

Here is my code, uses jQuery:

$('#popInvite').live('click', sendRequest);
function sendRequest() {

    FB.ui({
        method: 'apprequests',
        message: 'Become my Buddie',
        filters: ['app_non_users'],
        title: 'Become my Buddie'
    },
    function (response) {
        if (response && response.request_ids) {
            //if sucess do something
            //How many people did the user invited?
            var $howManyInvites = String(requests).split(',').length;
        } else {
            //  alert('canceled');
            return false;
        }
    });
    return false;

} ;
like image 113
Tom Avatar answered Dec 05 '22 21:12

Tom


here is the code and gone function is to get your appId from the path you can change it and do not forget the fbroot div :

invite

  <script src="http://connect.facebook.net/en_US/all.js" type="text/javascript">
  </script>
  <script type="text/javascript">


          FB.init({
              appId: gone(), cookie: true,
              status: true, xfbml: true
          });

          function shareWithFacebook() {
              FB.ui({ method: 'apprequests',
                  message: 'Here is a new Requests dialog...'
              });
          }


      function gone() {
          var pathname = window.location.pathname;
          var appId = pathname.split('/')[1];
          return appId;

      }

  </script>
like image 33
Eslam Soliman Avatar answered Dec 05 '22 20:12

Eslam Soliman