2

Thanks to How can I display the users profile pic using the facebook graph api? I found out I can retrieve profile picture via

http://graph.facebook.com/[UID]/picture

but this redirects to an image like for example:

http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs1346.snc4/161671_1096373372_1486835_q.jpg

My first question is when I want to display this image should I do(returned from API)

<img src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs1346.snc4/161671_1096373372_1486835_q.jpg" />

or should I call the api:

<img src="http://graph.facebook.com/alfredwesterveld/picture" />

Does http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs1346.snc4/161671_1096373372_1486835_q.jpg show my updated profile picture, if update my profile picture on Facebook or does show my old profile picture. I ask these question because when I could call an absolute URL(which resolves to an image immediately) I could safe myself a redirect(round-trip). I believe this could add up especially when I want to get all profile pictures from the visitors of my website.

Community
  • 1
  • 1
Alfred
  • 60,935
  • 33
  • 147
  • 186

2 Answers2

4

When you want to display the picture of a user use the second method, that's the good one:

<img src="https://graph.facebook.com/[UID]/picture" alt="" />

Doing like this you'll be sure that each time you'll receive the updated picture of the user, if it was changed recently.

later edit

Related to the cache issue, if you want to save the direct urls in order to improve caching of the pictures I don't suggest doing so because those urls are changing each time a user changes the profile picture, so you might end up displaying an older picture even though the user actually changed it recently.

misterjinx
  • 2,606
  • 3
  • 27
  • 29
  • 1
    You asked which of the two methods is better to use. And I told you which one and gave an example + some comments about why you should use this. If this is not want you want from your question then what is ? – misterjinx Feb 01 '11 at 10:13
  • Check out what I edited. I think that's what you wanted from the start :) – misterjinx Feb 01 '11 at 10:21
1

hi why you not use fbml tag for this?

<fb:profile-pic uid='UID' width='50' height='50'></fb:profile-pic>

EDIT hello if you want to get photo uploaded by the user then you can get by this

$photos=json_decode(file_get_contents('https://graph.facebook.com/me/photos?access_token='.$cookie['access_token']));
foreach ($photos->data as $friend)
{
?>
<img src="<?=$friend->source?>" width="50" height="50">
<?php    
}

All images uploaded by the user can be easily captured

Awais Qarni
  • 17,492
  • 24
  • 75
  • 137