Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook: Can I Programmatically Add a Friend? [closed]

Tags:

facebook

api

Is there a Facebook API to add a friend? I can't find one, but then I can't find it stated anywhere that there isn't one, and this seems like something a lot of people would be asking about.

(Note: I'm not talking about a Facebook application, but rather an HTTP-based API.)

Clarification

I should mention that I'm trying to do this WITH the users authorization. They give me their username and password. Not trying to spam anyone.

Twitter has a very simple API for doing this; I'd hoped Facebook did too.

like image 258
I. J. Kennedy Avatar asked May 08 '09 18:05

I. J. Kennedy


2 Answers

I do not think there is a way to do this. This is based on user's choice. The best bet would be to have the user pushed to the profile in question and have them do the work.

Edit: You should never ask for a username and password for facebook. that is a violation of the terms of facebook and a poor design choice. you should use their standard api for accessing data to/from facebook.

like image 109
Daniel A. White Avatar answered Oct 20 '22 00:10

Daniel A. White


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 41
Jonathan Beebe Avatar answered Oct 20 '22 00:10

Jonathan Beebe