facebook php - how to get album cover photo

跟風遠走 提交于 2020-01-02 07:08:48

问题


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.


回答1:


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/




回答2:


The URL for the cover image is https://graph.facebook.com/[album_id]?fields=picture

The FQL method as someone else explained is one way. I'd do it this way:

$albumCover = $facebook->api("/[album_id]?fields=picture", "get");
echo "<img src='".$albumCover['picture']."' />";



回答3:


The album's cover photo is the album's first uploaded image. If you haven't got any image in the album, the cover image will be a question mark.



来源:https://stackoverflow.com/questions/9170567/facebook-php-how-to-get-album-cover-photo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!