Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use facebook API getting friend's list in javascript

I am not familiar with using Facebook Javascript SDK. My story is when I access to the website It displays all my friends(pic and name) on a webpage. I registered Facebook API and App ID I put website URL as http://localhost:81/ because I am testing my own local machine. Do you have any good example website or good examples? Please share with me Thank you.

like image 787
SooIn Nam Avatar asked Dec 16 '22 03:12

SooIn Nam


1 Answers

First your app should use required permissions like,

user_birthday,  friends_birthday, user_location , friends_location...  

( for more permissions)

Get info about current user:

FB.api('/me', function(response) {
  //  Stuff here
});

Get info about current user's friends:

FB.api('/me/friends', function(response) {
  //  Stuff here
});

you will get the response like,

{data: [{id: "FRIEND1_ID", name: "FRIEND1_NAME"}, {id: "FRIEND2_ID", name: "FRIEND2_NAME"}]....}

If you want get some more properties of your friends, use FIELDS parameter, like

FB.api('/me/friends', {fields: 'name,id,location,birthday'}, function(response) {
   //  Stuff here
});

If want to get individual user's friend info:

FB.api('/FRIEND1_ID', function(response) {
  //  Stuff here
 }); 

Try this Example Site

like image 149
Rishi Php Avatar answered Mar 05 '23 19:03

Rishi Php