I've been just starting on Facebook Graph API.
How can I call several attributes with just 1 FB.api call? Right now, I have
FB.api('/me', function(me){
if (me) {
var myEmail = me.email;
var myID = me.id;
var myFirst_name = me.first_name;
//Other attributes
}
});
and
FB.api('/me/friends',{ fields: 'name,id' }, function(response){
var friends = response.data;
}
});
How do I combine both API calls into one, like say, just 1 FB.api()
call?
All responses will really really help.
How do I combine both api calls into one, like say, just 1 FB.api() call?
You could combine them both into one Batch Request – but that’ll make dealing with the response a little more complex, and I’m not sure if it would bring any “performance” gain in such a simple use case anyway.
EDIT:
There is a new way now¹ using the field expansion feature:
/me?fields=id,email,first_name,friends.fields(id,name)
– this would get you the requested fields id, email and first_name for the current user, and also the id and name for their friends. (Actually, just ,friends
would do if you only want their id and name, because those are the default fields the API delivers – but if you want other fields as well, you can add them using ,friends.fields(…)
.)
¹ actually for quite a while now, but this question has come to my attention again now, so I thought I’d add that.
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