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?
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.
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}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With