I’m writing some code to handle an application invitation request (FB.ui, method = apprequests), and would like to show the user, after sending the invitation, a block containing the pictures and names of the users to whom the request was sent. It appears that the only way to do this is to get the names of all the users’s friends via an API call to /me/friends and chew through the returned object, pulling the names for each invited user. C’est la guerre.
I’ve got some code doing this, but I’m worrying a little about performance in the case where the user has a large number of friends — /me/friends will return up to 5000 friends without calling the ‘next’ link; Facebook says that the average user has around 120-130 friends. It seems like there are two ways to deal with this:
1: Do it all in the browser, in Javascript; this is surely the most straightforward, but I worry about the efficiency of the Javascript implementation(s) in dealing with large numbers of friends — it would have to deal with a pretty large object containing all the friends, and would spend a lot of time searching through that large object looking for the right ones.
2: POST the list of invitees over to my server, which would make the call to FB to get the friends and construct and return the list of user names. My gut says that the server would be a more competent (= faster, less prone to locking up) engine for doing this stuff, perhaps enough so that it would be worth the cost of making the call from javascript over to the server and back again.
But, to be honest, I don’t really know. Any opinions out there, hopefully informed ones? I could do it either way, but if there’s something resembling a best practice, I’d like to follow it. Thanks!
You do not need to query /me/friends. When you make the FB.ui call, there is a callback containing the request_id’s and (more importantly in this case) the fbid’s of the users that were invited.
You can search for that user directly simply with a call to :
https://graph.facebook.com/{FRIEND_FBID}.These calls, even with FQL are relatively small and you shouldnt have to worry about performance. Ajax calls with the Javascript SDK would work fine, as would posting the request parameters to your server, and executing them there.
They do take some time… but nothing u really have to worry about.
If your
apprequestsare being used for in app notifications, then you’ll probably have a database set up and store your users referenced by their FBID you could also query your own database and retrieve the names, profile pictures that you saved on the users first visit.