How to access albums from a Fan Page on Facebook?

Asked

Viewed 122 times

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}";                
            }

There was some HTML in the code, but that’s beside the point. It worked very well, but now nothing appears. Does anyone know why? or has another method?

  • There’s a gap between the ? and the parameters http://graph.facebook.com/{$fb_page_id}/albums? fields=id,name,description,link,cover_photo,count,created_time, seems wrong.

  • 1

    https://developers.facebook.com/docs/graph-api/reference/v2.4/album

  • Hello William, it was a mistake to organize here in the question. But he is caught even.

1 answer

2

Your code is wrong but that’s not the problem. Facebook recently changed its policies and now it needs a token for such a request.

I modified the beginning of your code, if you run you 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;
  • Thank you for the comment Marcelo. I am a layman in this area, integration between Facebook and Website, as much as I have read the documentation of it. Would you have an example of how this integration would be? Since my goal is to rescue the albums from Fan page, to be displayed on my Site.

  • 1

    Thank you all for the answers. I just entered the Access Token and it all worked out fine.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.