SooIn Nam
SooIn Nam

Reputation: 3171

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.

Upvotes: 4

Views: 14375

Answers (2)

SAB
SAB

Reputation: 1

Direct Access Method:

Log into Facebook under your name. If you need an "Access Token", Click on the Extended Permissions and click the "read_friendlist" check box to get your Access Token and then submit your query. You may need to "Allow" access, so just follow the prompts given. Voila! You now have the usernames for everyone on your Friends List. The "username" parameter in the query will give you the contact email "message to that person" and you append @facebook.com and send them a message. Very simple.

http://developers.facebook.com/tools/explorer?fql=SELECT%20username%20FROM%20user%20WHERE%20uid%20IN%20%28SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20%3D%20me%28%29%29%20ORDER%20BY%20name

-SAB

Upvotes: 0

Rishi Php
Rishi Php

Reputation: 1418

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

Upvotes: 12

Related Questions