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


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.)


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:


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.


Check out SimpleTest's scriptable browser. It is part of their test framework, but you can use the browser component independently.

Snoopy is another good option.


Yes, I think we shouldn't ask for user Pass and User name.

But, If you need to do it in your application you can use database/XML to do that. But only your application will treat the added user as a friend not the facebook.

In my application i added all friends in DB and also added my self as a friend of my self. so that i can do the task what is defined to myFriends role(in my application).

ID FBUserId Name

9705 1215966620 Abul Bashar

9706 1248090545 Tuhin Ahmed
9707 1251036547 Orijit Diponkor Shuvrangshu Tridib
9708 1252800907 Shahin Mahmud 9709 1263680515 Binayan Dey 9710 1275860308 Mitu Kumar Debnath 9711 1279017492 Ahmed Riaj 9712 1280150772 Mahbubur Rub Talha 9713 1287414234 প্রবাসী সারোয়ার 9714 1294159220 Md.Humayun Kabir 9715 1294340379 Shah Muhammad Mazed

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »