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 bine both API calls into one, like say, just 1 FB.api()
call?
All responses will really really help.
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 bine both API calls into one, like say, just 1 FB.api()
call?
All responses will really really help.
Share Improve this question edited Aug 15, 2021 at 15:07 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jun 21, 2012 at 8:50 bryan.blackbeebryan.blackbee 1,9645 gold badges32 silver badges48 bronze badges 01 Answer
Reset to default 7How do I bine both api calls into one, like say, just 1 FB.api() call?
You could bine them both into one Batch Request – but that’ll make dealing with the response a little more plex, 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 e to my attention again now, so I thought I’d add that.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744844363a4596744.html
评论列表(0条)