tags:

views:

22

answers:

2

I'm using the PHP SDK from facebook in my own application. When I retrieve the news feed for my own profile it contains the ID for each friend that has a message on my feed. Can I create a link to each persons profile page from just their facebook ID? Or do I have to make a separate API call for each ID and retrieve their username to create the link? This is how I'm doing it now (making the api call for each friend):

$feeds = $facebook->api('/me/home'); 
foreach($feeds as $feed){
    $friend_info = $facebook->api('/'.$feed['from']['id']);
    $friend_link = $friend_info['link'];
+1  A: 

I don't know whether more elegant solution exists or not, but I offer you to improve your code to use FQL like:

SELECT profile_url, uid FROM user WHERE uid IN (1,2,3,4,...)
zerkms
Ok, I'm trying to emulate the news feed from facebook just to see how the API works, I figured this might be a fairly common thing to do. But thank you for the answer. Since I'm new to the API is it fairly common to use FQL over a straight API call? What benefits do you gain? That's the stuff I've found lacking in the documentation
controlfreak123
Not common, but usually FQL helps to do the things like I show above. Benefits - flexibility. With general api calls you're not able to do the same `IN (1,2,3,)` trick. In the cases, when common graph methods solves my issues - i use them, since they are shorter and simpler.
zerkms
Gotcha. Sorry but I don't see what the IN(1,2,3) clause would gain me because I already know the UID of the friends I'm trying to get profile info for.
controlfreak123
With that FQL you will utilize: 1 query for feed, 1 query for ALL friends. And in your case you perform N queries to get users' links.
zerkms
Ah I see now. You get all the profile_url's and UID's that are in your friends_list in that query. I guess I just need to look into FQL a bit deeper!
controlfreak123
+1  A: 

If you have user id then profile url is: http://www.facebook.com/profile.php?id=<UID>

serg
Hehe, nice cheat. I expected it works with just `facebook.com/NNNNN`, but it does not.
zerkms
Perfect! Although i must admit I did learn a lot from zerkms answer as well!
controlfreak123

related questions