Facebook Graph API – How to retrieve the different size photos from an album


Ok, first off let me tell you I have no problems getting a user's photo album(s) and looping through the output to display all of the photos in the size I want.

However, if I want to call a photo like:

<img src="https://graph.facebook.com/<?=$this->session->page->photo_id?>/picture?access_token=<?=$this->session->member->facebook_access_token?>" />

I cannot figure out how to tell it the size I want it to show.

In this sample code from Facebook you will see that whey retrieving the album each photo in the array comes back with the different sizes in this sample array. I could just save the thumbnail url from this, but I don't want to store it, just retrieve when needed.

   "id": "10150146071831729",
   "from": {
      "name": "Facebook",
      "category": "Product/service",
      "id": "20531316728"
   "picture": "http://photos-g.ak.fbcdn.net/hphotos-ak-ash1/168119_10150146071831729_20531316728_7844072_5116892_s.jpg",
   "source": "http://a7.sphotos.ak.fbcdn.net/hphotos-ak-ash1/168119_10150146071831729_20531316728_7844072_5116892_n.jpg",
   "height": 483,
   "width": 720,
   "images": [
         "height": 483,
         "width": 720,
         "source": "http://a7.sphotos.ak.fbcdn.net/hphotos-ak-ash1/168119_10150146071831729_20531316728_7844072_5116892_n.jpg"
         "height": 120,
         "width": 180,
         "source": "http://photos-g.ak.fbcdn.net/hphotos-ak-ash1/168119_10150146071831729_20531316728_7844072_5116892_a.jpg"
         "height": 87,
         "width": 130,
         "source": "http://photos-g.ak.fbcdn.net/hphotos-ak-ash1/168119_10150146071831729_20531316728_7844072_5116892_s.jpg"
         "height": 50,
         "width": 75,
         "source": "http://photos-g.ak.fbcdn.net/hphotos-ak-ash1/168119_10150146071831729_20531316728_7844072_5116892_t.jpg"
   ....... continued...

There has to be a way to retrieve these different sizes.


Best Solution

Facebook provides a type option for the picture field, for example, you can specify something like:

<img src="https://graph.facebook.com/xxx/picture?access_token=yyy&type=normal />

where the type parameter can be one of square, small, normal, or large for profile pictures or thumbnail, normal, album for album pictures.

Source: http://developers.facebook.com/docs/reference/api/user/ (under Connections section)

Edit: Added different options for album pictures

Related Question