Php – facebook php – how to get album cover photo

facebookfacebook-graph-apifacebook-php-sdkPHP

I need to get the album cover photo with the PHP SDK (Facebook).
I try with:

https://graph.facebook.com/[ALBUM_ID]/picture?type=album, but I get a default image… for example… to get profile pic of user https://graph.facebook.com/[USER_ID]/picture?type=square

Somebody can tell me the correct way to get cover photo for albums please.

thanks.

Best Answer

You could just use FQL, it is my preferred method and offers a lot of flexibility. This code sample should be what you need:

$album_id = '6464156415616';
    try{
        $fql    =   'SELECT pid, src_small FROM photo WHERE pid in (SELECT cover_pid FROM album WHERE aid='.$album_id.' AND owner=me())';
        $param  =   array(
            'method'    => 'fql.query',
            'query'     => $fql,
            'callback'  => ''
            //,'return_ssl_resources'=>1 //set this option if you want the source to come from https
        );
        $fqlResult   =   $facebook->api($param);
        $fqlResult['type'] = $uploadVal['type'];

        //fetch values
        $src_small = $fqlResult['src_small'];                   

    } catch(Exception $o){
      print_r($o);
    }

You can find a reference to all of the FQL tables here: http://developers.facebook.com/docs/reference/fql/