How to access albums from a Fan Page on Facebook?

1

I used the following code to access the albums of a fan page on facebook:

$cUrl = new cUrl;
$fb_page_id = "xxxx";

$json_link = "http://graph.facebook.com/{$fb_page_id}/albums?fields=id,name,description,link,cover_photo,count,created_time";
$json = $cUrl->file_get_contents_curl($json_link); 

/*$obj = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);*/
$obj = json_decode(preg_replace('/("\w+"):(\d+)/', '\1:"\2"', $json), true);

$album_count = count($obj['data']);

        for($x=0; $x<$album_count; $x++):

            $id = $obj['data'][$x]['id'];
            $name = $obj['data'][$x]['name'];
            /*$description = $obj['data'][$x]['description'];*/
            $link = $obj['data'][$x]['link'];
            $cover_photo = $obj['data'][$x]['cover_photo'];
            $count = $obj['data'][$x]['count'];
            $data_s-> usarData($obj['data'][$x]['created_time']);

            // if you want to exclude an album, just add the name on the if statement
            if(
                $name!="Profile Pictures" &&
                $name!="Untlited Album"
            ){
            $show_pictures_link = "?album_id={$id}&album_name={$name}";
            echo $data_s->data();
            echo "{$name}";                
            }

I had some HTML in the code, but that's beside the point. It worked very well, but now nothing appears. Does anyone know why? or do you have another method?

    
asked by anonymous 20.07.2015 / 20:40

1 answer

2

Your code has an error but the problem is not this one. Recently Facebook has changed its policies and now it needs a token for such a request.

I modified the beginning of your code, if you run it will see the message "An access token is required to request this resource." .

// $cUrl = new cUrl;
$fb_page_id = "xxx";
$json_link = "http://graph.facebook.com/{$fb_page_id}/albums?fields=id,name,description,link,cover_photo,count,created_time";
// $json = $cUrl->file_get_contents_curl($json_link); 

$ch = curl_init($json_link);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$json = curl_exec($ch);
curl_close($ch);

/*$obj = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);*/
$obj = json_decode(preg_replace('/("\w+"):(\d+)/', '\1:"\2"', $json), true);
var_dump($obj);
exit;
    
21.07.2015 / 19:34