Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Application Send Friend request using Facebook Api

Tags:

facebook

I want to send Facebook friend invitations to some of our friends list without using FBML tags (<fb:request ....)

I am writing code in ASP.NET using fbServices.

How can I send friend requests without using FMBL tags?

like image 892
gopalak Avatar asked Dec 07 '22 06:12

gopalak


2 Answers

Friend requests cannot be done through the Facebook API. The FBML fb:request-form tag is the only way to do this.

like image 160
Pierre-Antoine LaFayette Avatar answered May 19 '23 14:05

Pierre-Antoine LaFayette


I spent a great deal of time looking, and finally came accross a very simple solution.

Using the Facebook Javascript API you can do a friend request with:

<script>
    FB.ui(
     { 
      method: 'friends.add', 
      id: fbid // assuming you set this variable previously...
     }, 
     function(param){

      console.log(param);

            // If they cancel params will show: 
            //    {action:false, ...}
            // and if they send the friend request it'll have:
            //    {action:true, ...}
            // and if they closed the pop-up window then:
            //    param is undefined
     }
    );
</script>

The callback script can then simply performs an ajax call to your server where you save info about the action, if needed.

You can test this by using the javascript console app on Facebook:

http://developers.facebook.com/tools/console

Paste in the script above, including the tags, or click the "Examples" button on the bottom of the text area and find the "fb.ui — friends.add" example.

like image 37
Jonathan Beebe Avatar answered May 19 '23 13:05

Jonathan Beebe