I need to get a hold of a user of my app's list of friends to filter the users that show up in a friend picker. I know I can call the following and get the list:
https://graph.facebook.com/me/friends?access_token=<access_token>
I tried it out in the address bar with my own account and it seems to work exactly as I need it to. Problem is, I don't know how to make use of it in a js file itself. I tried calling it and getting the data out with a jquery call but it doesn't seem to return anything helpful.
$.get("https://graph.facebook.com/me/friends",
{access_token: <access_token>},
function(data){ document.write("Data Loaded: " + data);});
How should I be calling this in my js files and then actually make use of the information? Thanks.
UPDATE: As per the changes introduced in V2.0, /me/friends
will return app friends only.
The right way to do that is by using the Facebook Javascript-SDK, something like this:
function getFriends() {
FB.api('/me/friends', function(response) {
if(response.data) {
$.each(response.data,function(index,friend) {
alert(friend.name + ' has id:' + friend.id);
});
} else {
alert("Error!");
}
});
}
Please note that:
If you want to extract information from the Graph with JavaScript, you will have to use the JS SDK and FB.api method to make the calls.
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