Using Facebook API to invite friends?
Asked Answered
T

4

26

I want an "Invite Friends" link on my website where you click it and you get a Facebook dialog that asks you to choose which of your friends you'd like to invite. Those friends then either get an application request, Facebook email or at least a wall post inviting them to join my website.

I'm a bit confused over what is the proper way to do this. It seems the only non-deprecated way now is through the Requests Dialog. So I call the FB.ui Javascript method like the example they give:

FB.ui({
    method: 'apprequests', 
    message: 'You should learn more about this awesome game.',
    data: 'tracking information for the user'
});

Then the invitees will get application requests when they login to Facebook. When they "accept" that request, they'll be directed to my Facebook canvas application where I read the initial request id passed from Facebook so I know what this is about and then I guess I can redirect the user to my website? I don't like this as I now have to learn how to build a canvas application, but is this the proper way to have an invite friends through Facebook feature?

Ideally the invite friends button brings up the Facebook friend selector (or login if the user isn't logged in to FB yet) and then posts on those friends' walls. That message posted would have a simple link back to my website. Is this possible?

Tide answered 15/8, 2011 at 17:37 Comment(0)
R
21

I had same problem. Though it is very late for answering question, it will help somebody. That's why answering this question.

Call this Javascript function when want to send invitations.

function sendRequestViaMultiFriendSelector() {
    FB.ui({
        method: 'apprequests',
        message: "This message is displayed in invitation"
    },send_wall_invitation);

}

function send_wall_invitation(response) {
   // alert(response.to);
    var send_invitation_url=base_url+'send_invitation';
    jQuery.ajax({
        url:send_invitation_url,
        data:{
            to:response.to
            },
        dataType:"json",
        type: 'POST',
        success: function(data){
//            alert("");
        }

    })
}

Sending array of friends invited by ajax and then send post for each friend.

I can post on the user's friends walls via the PHP API. Try this :

$facebook->api('/[FRIEND_ID]/feed', 'post', array(
          'message' => 'test message',
          'link' => 'http://google.com',
          'name' => 'test name',
          'caption' => 'test caption',
          'description' => 'test long description',
      ));

Posting on friends wall is not possible now by Feb 2013. How to post on a friend's Timeline after the February 2013 migration takes effect?

$facebook->api('/[Loggedin_user_id]/feed', 'post', array(
              'message' => 'test message',
              'link' => 'http://google.com',
              'name' => 'test name',
              'caption' => 'test caption',
              'description' => 'test long description',
          ));

But user can still post on his wall and tag friends in post or image.

See :

  1. FB upload photo from application and post it to user's wall
  2. Tags friends photo
Ribose answered 21/2, 2012 at 11:37 Comment(0)
M
4

I guess the newly introduced "Send" button (and it's dialog equivalent) is what you need:

<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <body>
    <script src="http://connect.facebook.net/en_US/all.js"></script>
    <div id="fb-root"></div>
    <script>
      // assume we are already logged in
      FB.init({appId: '123050457758183', xfbml: true, cookie: true});

      FB.ui({
          method: 'send',
          name: 'People Argue Just to Win',
          link: 'http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html',
          });
     </script>
  </body>
</html>
Magdeburg answered 15/8, 2011 at 22:42 Comment(2)
I saw this, but it doesn't seem appropriate for an "invite friends" type functionality. You have to type in the friends' names that you want to invite.. I need it to be very easy to invite your friends with a select all and a point-click selection interface. I guess otherwise this is good, just the friend selection process.Tide
@at, read the document I linked to, you can still use the phrase "invite friends". You need to encourage the user's friends to come to your website (visit a URL) so it's a user-to-user communication.Magdeburg
C
2

Use this in your HTML file. It works great for me.


<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:fb="https://www.facebook.com/2008/fbml">

<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>


<p>
<input type="button"
  onclick="sendRequestViaMultiFriendSelector(); return false;"
  value="Send Request To Your Facebook Friends"
/>
</p>

<script>
  FB.init({
    appId  : 'APP_ID',
    frictionlessRequests: true
  });

  function sendRequestToRecipients() {
    var user_ids = document.getElementsByName("user_ids")[0].value;
    FB.ui({method: 'apprequests',
      message: 'Awesome Application try it once',
      to: user_ids
    }, requestCallback);
  }

  function sendRequestViaMultiFriendSelector() {
    FB.ui({method: 'apprequests',
      message: 'Awesome application try it once'
    }, requestCallback);
  }

  function requestCallback(response) {
    // Handle callback here
  }
</script>
Clifton answered 20/3, 2013 at 11:22 Comment(4)
the above to: user_ids is generated from my HTML or is it from the FB dialog?Morph
This give me an error : The parameter app_id is requiredWitten
Yes you will need to put application app_id from facebook developers appClifton
to make it work you need app Id and Category is gamesBottoms
B
0
<div id="fb-root"></div>
   <script src="http://connect.facebook.net/en_US/all.js">
   </script>
   <script>
     FB.init({ 
       appId:'APP ID', cookie:true, 
       status:true, xfbml:true 
     });



function FacebookInviteFriends()
{
FB.ui({ method: 'apprequests', 
   message: 'VISIT THIS WEB SITE'});
}
   </script>

<a href='#' onClick="FacebookInviteFriends();"> INVITE YOUR FACEBOOK FRIENDS</a>
Beekeeper answered 4/7, 2012 at 22:35 Comment(1)
you may want to add some more prose to this replyHubble

© 2022 - 2024 — McMap. All rights reserved.