I am creating a facebook app and i want to display the users albums with the cover image, i have tried with code #1 but it is really really slow as i make a facebook api call in the foreach which makes my app take forever, so I am looking for another way to make the api call just once and get all the info, so i tried with FQL multi query (code#2) but now i have a problem because if the album has no image it won´t return nothing, so please check my codes and if you have any idea how i can do this i will greatly appreciate it
code#1
$albums = $facebook->api('/me/albums?limit=0&fields=id,name,count,cover_photo');
foreach($albums['data'] as $album)
{
// get all photos for album
$photos = $facebook->api("/{$album['id']}/?fields=picture,name,count");
$foto = $photos['picture'];
$nombre = $album['name'];
$id = $album['id'];
$count = $album['count'];
$cover_photo = $album['cover_photo'];
$nombre = $nombre." (".$count.")";
echo "<li> <a href=\"album.php?numero_album=$id&nombre_album=$nombre \" title=\"$nombre\"><img src=\"https://graph.facebook.com/{$cover_photo}/\" alt=\"$nombre\" /> </a> </li>";
}
code#2
$multiQuery = '{
"albumes":"SELECT name,cover_pid,object_id,size FROM album WHERE owner=me()",
"portadas":"SELECT src_big FROM photo WHERE pid IN (SELECT cover_pid FROM #albumes)"
}';
$param = array(
'method' => 'fql.multiquery',
'queries' => $multiQuery,
'callback' => '');
$queryresults = $facebook->api($param);
foreach($queryresults[0]['fql_result_set'] as $album)
{
$nombre = $album['name'];
$id = $album['object_id'];
$count = $album['size'];
$nombre = $nombre." (".$count.")";
echo "<li> <a href=\"album.php?numero_album=$id&nombre_album=$nombre \" title=\"$nombre\"><img src=\"https://graph.facebook.com/{$cover_photo}/\" alt=\"$nombre\" /> </a> </li>";
}