7

I am using the Facebook JavaScript SDK. I am able to get the user's information using:

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

I get the user's friends using:

FB.api('/me/friends', function(response) {
 ...
}); //.. it only has two values name and id.

I want to get friends Date of birth and location. Is there a FB.api method to get it or can I get it using FB.Data.query?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nick
  • 385
  • 4
  • 8
  • 16
  • 1
    only returns the friends using the app. http://stackoverflow.com/questions/23417356/facebook-graph-api-v2-0-me-friends-returns-empty-or-only-friends-who-also-u – Ankit Popli Nov 20 '14 at 10:52

5 Answers5

8

First your app needs to have the correct permissions, friends_birthday and friends_location in this case.

Next, use the fields parameter in your Graph API request to request the birthday and location fields:

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

Depending on privacy settings on some of the friends' accounts, you may or may not be able to access birthday or location data, so make sure you handle the cases where the info is missing. See this question for why.

jches
  • 4,542
  • 24
  • 36
4

Doing:

FB.api('/me/friends', function(response) {
 ...
}); //.. it only has two values name and id.

You will get:

{data: [{id: "xxxxx", name: "Friend name"}, {id: "xxxxx", name: "Friend name"}]}

Than you could access the resource using received id:

FB.api('/xxxxx', function(response) {
 ...
}); // {first_name: "Name", gender: "male", id: "xxxxxx",.. etc}
Anton
  • 41
  • 1
  • 2
4

You'll need an authenticated user with the user_birthday, friends_birthday, user_location & friends_location permissions. Then you can do something like:

FB.api('/me/friends', { fields: 'name,id,location,birthday' }, function(result) {
  // resut has the data
})

Try it out here.

daaku
  • 2,797
  • 20
  • 20
0

I barely know anything about FB API but have you looked at this: http://developers.facebook.com/docs/reference/javascript/FB.Data.query
And this:
http://developers.facebook.com/docs/reference/fql/

gideon
  • 19,329
  • 11
  • 72
  • 113
0

You can get complete friend's id and name in an array by using FB.api. One needs to initialize the app using FB.init and later checks if user is logged in using FB.getloginstatus(). then only FB.api is useful.

Here is a link which explains how to fetch friends using Javascript SDK.

oers
  • 18,436
  • 13
  • 66
  • 75
Drupal Sinha
  • 27
  • 1
  • 3