Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Graph API - How do you 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.

Thanks.

like image 945
Tomas Avatar asked Jul 08 '11 19:07

Tomas


People also ask

What data can I get from Facebook graph API?

The Graph API is the primary way to get data into and out of the Facebook platform. It's an HTTP-based API that apps can use to programmatically query data, post new stories, manage ads, upload photos, and perform a wide variety of other tasks.

How do I find the original size photos on Facebook?

Tap on the photo, then tap View Full Size. You can also pinch the photo to zoom in or out. To exit fullscreen mode, tap back.


2 Answers

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

like image 58
cyang Avatar answered Oct 07 '22 11:10

cyang


Thought I'd share a little trick in getting larger image sizes from the Graph API. Facebook as a little convention with image URLs that's not very obvious. For instance, take the following URL:

https://fbcdn-photos-g-a.akamaihd.net/hphotos-ak-prn2/t1/1185356_10201176263222205_1153673992_s.jpg

Notice the _s.jpg at the end? That determines the size of the image. You can change this to _o.jpg to get the "original" full size version. In other words, update the image URL to:

https://fbcdn-photos-g-a.akamaihd.net/hphotos-ak-prn2/t1/1185356_10201176263222205_1153673992_o.jpg

Every Facebook image has an _o.jpg version. Worst case, you get something the same size as the thumbnail. If that's the case, you're no better off than you were before.

like image 29
Wilhelm Murdoch Avatar answered Oct 07 '22 11:10

Wilhelm Murdoch