Sometimes you may need to retrieve user’s friend-list in facebook. You can retrieve user friends list in several ways. Using new graph api you can retrieve friend-list or you can call legacy api to retrieve friend-list.
Using graph api:
function getUserFriendList($facebook){
$friends = $facebook->api('/me/friends');
return $friends;
}
Using legacy api:
function getUserFriendList($facebook, $uid){
try {
$param = array(
'method' => 'friends.get',
'uid' => $uid,
'flid' => '',
'callback'=> ''
);
$friends = $facebook->api($param);
return $friends;
}
catch(Exception $o) {
d($o);
}
return '';
}








Can I get friendlist of any user using this method? Or only friendlist of user that using my app?
No you can’t retrieve any user’s friendlist. You can retrieve only app user’s friendlist when the user logged in your facebook application.
Thank you for reply. So I can’t make friends tree (show my friends and friends of my friends in tree-view)?
I guess you also have to include it in the application permissions… access_token is not enough!
i am getting error for retryping freinds name from facebook through the api bellow are is my code
’276868289004400′,
‘secret’ => ’6de4440db71ab726bb25c7b3ab3da257′,
));
$friends = $facebook->api(‘/me/friends’);
return $friends;
?>
bellow the result which comes out
Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in /home/itinfopa/public_html/fbaccount/facebook-php-sdk-v2.1.2-0-gb14edfa/facebook-php-sdk-b14edfa/src/facebook.php on line 543
use sdk version 3.0
ok, my user is logged into app, but if i use $facebook->api(‘/me/friends) i contune to get all friends , not just those who use it. How is possible?
what if my friend has made the friend list public !! then is there any way to see that public list or even if its been private we can see the mutual frnds so at any case is there any solution to see the friends list or mutual frnds using a facebook app and if so please give the code to do please !!
How i can retrieve logged in user friend list using my app?
this method retrive all user friend list right?
which of these methods is better? Legacy API or Graph Api?
i think graph api is better as it retrieves friends name also.
dude..i dont no dis language.. i want process but in asp.net..pls help..:):):)
Please check the asp.net or c# sdk http://developers.facebook.com/news.php?blog=1&story=395
How can I retrieve user’s friends that is also using the app in Graph API? Uugh, the Facebook Graph API docs is horribly documented. Right now, I’m using friend pile using the new Javascript SDK…I want to know how to do this using graph api? Thank you ^^
This is graph api calling using js-sdk.
FB.api('/me/friends', function(response) { //friends });can you tell me how to retrieve user’s friends that is also using the app Quickly.
I retrieve whole friendlist of any user using this method, then Contrast my db to check if everyone is my app user? This seems inefficient.
There are better ways to do?
Receiving the user’s friendslist works fine in session context with /me/friends.
Is there a way to receive this friendslist via a cronjob, when the user is NOT logged in. It should be possible as the user allowed me to access his friends.
Hi mahmud ahsan,
Sir do you have any idea how to retrieve “facebook freinds feeds” while i have user offline permission.
Please let me know thanks.
I’m not sure, please check the following document http://developers.facebook.com/docs/reference/rest/stream.get
Hi,
Would you know how to get the actual username of the user with this:
$facebook->api(array(‘method’ => ‘friends.get’,'name’ => $uid));
Thanks.
Salam , I have seen posts on my wall from applications , but with my friends name . i want to do the same , that my application gets the friends of the current user and posts to walls of all of them . how is that possible , can you please direct me to the right direction.
Thanks,
Furqan
Please check out my other tutorials.
hi mahmud,
great tutorials, i love them!
is there any way to get the list of fans of my app / the people who like or use my application?
kind regards and thanks,
chris
Hello Chris, I don’t find any api or sql tables for this requirement. But you can checkout FQL tables from here http://developers.facebook.com/docs/reference/fql/page
Thanks for your fast response, man.
Really good job.
rock on,
Chris
Dear Mahmud,
thanks for the great tutorials.
I successfully retrieve friend list by graph api.
$friends = $facebook->api(‘/me/friends’);
However, there are only two attributes (name& id) in the JASON file.
Would u know is there any way to get their photo thumbanail ?
Thanks so much & best regards,
Casey
so you could easily get user photo from their uid.
Thanks mahmud, that’s a great help !
There are still some problem using graph api to post messages on friends’ wall.
I’ve tried add
‘req_perms’=>’publish_stream’,
into facebook.php (line428)
But, I still cannot post messages on my friends’ walls by
$statusUpate = $facebook->api(‘friend_id/feed’,'post’,array ……);
Is there any solution ?
Thanks again and best regards,
Casey
Hey, answer to myself.
Both ‘me’ and the user of ‘friend_id” should authorized the application.
^^
Hi, I’m using JS SDK… i’ve seen you put how to retrieve friend list with this JS… i’m just a beginner with all this facebook’s stuff, so coul you help me wtih this> i want to retrieve a list with friends’ photos and current location so i can use than info… please help me.
Thanks
Hello Javier, please checkout my other tutorials in popular section. Then you’ll learn how to setup and develop facebook application.
Mahmud
your code will give me user’s friends’ names,ids, but I need the birthday of friends. I am using PHP sdk. Could you post a piece of code showing how to ask for the permissions and getting friends’ birthday. Thanks.
Please check FQL, using FQL you can retrieve user’s birthday if user isn’t restricted that. You’ll get idea http://thinkdiff.net/facebook/facebook-birthday-api/ you’ve to use latest php sdk to make rest api call.
Is there a way to receive this friendslist via a cronjob, when the user is NOT logged in. It should be possible as the user allowed me to access his friends.
i want to access user frinds lish,,i have use the method friends.getLists but empty list is shown,having no error,,,
can u guild me whats wrong with this mentog,,thanks
After getting friends list, how to show name of friend?
I use foreach but it’s not ok:
foreach($friends as $friend){
echo $friend['name'];
}
Hey dude! nice post, i have a doubt,
i want to send a message to a selected friends of my list, i want to do this as private message un fb or send an email to him , or simply notify him that he was added to my app,
this can be done in some way?
Thanks!
Hi mahmud ahsan,
hope you are doing good.
$_REQUEST["fb_sig_user"]; is not working for fbml tab based application.
what is the alternative for the same.
I just want to capture the facebook userid who is playing my application.
Please do the needful.
Thanks in advance.
What will be the best way to store friends list in the database?
Hello mahmud! Thanks for your tutorials! They are of great help…:)
anyway do you know how to check if two users are already connected on facebook, that is are friends?
Is there a way to do this using graph api?
Thank you
Hi mahmud,
I tried this code,and its not working for me.Pls let me know whether this is because of the change in facebook api.If so whats the new code? Pls help me I have been trying for Days
Hi Mahmud,
I am trying to retrieve profile information like education and work history for people in my friend list. How can I do that? Do I require permission from each one of them??
Thanks in advance!
$user_profile = $facebook->api(‘/me’);
this will return an array and part of this is like
[education] => Array
(
[0] => Array
(
[school] => Array
(
[id] => 110822202275004
[name] => sps college swat
)
[year] => Array
(
[id] => 113125125403208
[name] => 2004
)
[type] => High School
)
[1] => Array
(
[school] => Array
(
[id] => 109989835697638
[name] => NWFP University of Engineering & Technology
)
now use this $school_name = $userInfo['school']['name'];
$employer_name = $userInfo['employer']['name'];
print the arrar through print_r(); u ll know what u r retriving. do the same thing like
$school_name = $userInfo['school']['name'];
$employer_name = $userInfo['employer']['name'];
Thank you for helping us with our facebook programming!
How can i get profile information like education and work history for people in my friend list ?
I am already asking for permissions of friend work history and education history.
Please Help .
can you show some code which list fb friends in dropdown list.?
how to get friends birthdays list,
Thank you for ur tutorial
i tried to get facebook userdata but i got error…
Exception Object
(
[message:protected] => Facebook needs the JSON PHP extension.
[string:private] =>
=> 0
[file:protected] => /projects/p41/www/html/interworld.co.in/RechargeNation/facebook_rd/facebook.php
[line:protected] => 6
[trace:private] => Array
(
[0] => Array
(
[file] => /projects/p41/www/html/interworld.co.in/RechargeNation/facebook_rd/fbmain.php
[line] => 7
[function] => include_once
)
)
)
i dont have install json…..
can i use xml instead of json….plz explain the way where i can use xml …in place of json_decode…..so that i need not to install json
plz help
what is the $facebook in the code means?? is it the userid of person from whom we are going to get the friend list……..
is it possible to acess facebook user friends email ?
no
What is the $facebook variable? I’m trying to use the legacy api and the first variable in the function is $facebook, but I don’t know what to put in for that variable when calling the function. Also, is the $uid variable the user id?
How would I use this function? Would I use a “foreach” loop ?
Thank you for your help!
i want to retrive facebook user friend list (close_friends, acquaintances, restricted,user_created, education, work, current_city or family) .i guess this would not work in my scene.i have this permission (ead_friendlists,manage_friendlists).how to do this through graph api .please reply
How do I display the list of friends after retrieving the names and id.
This method $facebook->api(‘/me/friends’);
retrieves only freidns using the common application as me.
I want to retrieve the list of all my friends.
string query = “SELECT name,online_presence,status FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 =” + mid + “)”;
string xmrrd = api.Fql.Query(query);
DataSet ds = new DataSet(query);
ds.ReadXml(new StringReader(xmrrd), XmlReadMode.InferSchema);
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
Hi,I’m using this code in asp.net but datagridview displays only true.
Please tell me how what is going wrong in this code?
Hi, why would I need a users friends list? What can I do with it?
hiii…………. how to call that Javascript function(above code) means what is that parameter $Facebook how to pass it??