Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get album pictures using facebook API?

This should be fairly common but somehow I cannot get it to work. What I would like to do is the get album pictures from facebook. I am implementing this on a website.

I can get the albums using this code:

function getAlbumPhotos(){             FB.api('/me/albums',  function(resp) {                 //Log.info('Albums', resp);                 var ul = document.getElementById('albums');                 for (var i=0, l=resp.data.length; i<l; i++){                     var                         album = resp.data[i],                         li = document.createElement('li'),                         a = document.createElement('a');                     a.innerHTML = album.name;                     a.href = album.link;                     li.appendChild(a);                     ul.appendChild(li);                 }             });         }; 

the resp returns a data array which contains links to the photo albums BUT I would like the image sources for each album and I don't see anything I can use in the resp data. The data object contains a link to the album but not individual images.

According to facebook documentation, photos are "connections" to albums. I am not sure what means but their doc shows that you can get individual photos.

From this link:

[http://developers.facebook.com/docs/reference/api/album/][1] 

it shows the json(?) returns link, id, name, etc...which I am able to get. However, at the bottom of that page are "connections" to album which includes photos, comments, pictures. When I click on photos, it shows the JSON data structure including the img src. Question is, how do I get that? It seems so straightforward but I can't get it to work.

I tried

FB.api('/me/photos',function(resp) ... 

and

FB.api('/me/photo',function(resp) ... 

photos return nothing while photo returns undefine.

Code samples will be greatly appreciated.

like image 448
okysabeni Avatar asked Mar 11 '11 17:03

okysabeni


People also ask

How do I pull up an album on Facebook?

Tap in the top right of Facebook, then tap your name. Scroll down and tap Photos. At the top of your screen, tap Albums. Tap the album you'd like to view.

How do I link to a photo album on Facebook?

Log in to your Facebook account and go to your photos or album with the photos you want to share. After opening the album with the pictures, scroll down to the bottom end of the page and click the Public Link option. Right-click the link and then select Copy.


2 Answers

  1. From the first call you get all the albums (and the album IDs) '/me/albums'
  2. from there you can get the album picture (cover) '/'+album.id+'/picture'
  3. AND the photos of the album '/'+album.id+'/photos'
like image 170
ifaour Avatar answered Sep 20 '22 09:09

ifaour


you can also try

/_ABLUM_ID_/photos

on the graph api, i.e.

https://graph.facebook.com/12341234/photos

where 12341234 is the album object id of the album you want to get the photos of.

like image 45
Karl Kastan Avatar answered Sep 23 '22 09:09

Karl Kastan