TIMEX
TIMEX

Reputation: 272094

Can I "add friend" with Facebook's API?

Does their API allow my Facebook-connected user to add a friend?

Upvotes: 31

Views: 37657

Answers (4)

Jonathan Beebe
Jonathan Beebe

Reputation: 5226

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.

Upvotes: 28

Tim Jarvis
Tim Jarvis

Reputation: 18815

Here is a Wiki list of the API methods available to you http://wiki.developers.facebook.com/index.php/API#Administrative_Methods

Doesn't look like you can add friends via the API. Note the iPhone facebook app also doesn't have an add friends function, it was written via the API, so that lends more weight to the idea that you can't

Upvotes: 0

Gdeglin
Gdeglin

Reputation: 12618

No. Adding friends is not possible through the API.

However you can direct users to http://www.facebook.com/addfriend.php?id=[USER UID]

Where [USER UID] is a valid facebook user id.

Good luck!

Upvotes: 29

Related Questions