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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With