Skip to content

How to get Facebook Page Albums With PHP in CodeIgniter?

Last updated on July 7, 2017

Facebook SDK : Download

After Downloading FB SDK, place all files in relevant areas in your Codeigniter application based on the folder names.
All you need to do is enter application id and secret id in config file called facebook.php located at application/config/facebook.php.

load->library('facebook'); // load facebook library
       $this->load->helper(array('url','html')); // load url and html hlpers
       $this->facebookPageID = 'Search.Andhra'; // set page id
    }

    public function index()
    {
        $albums = $this->facebook->api($this->facebookPageID.'?fields=albums'); // api call to facebook to fech all albums of the given page
        // list all albums
        foreach($albums['albums']['data'] as $album) {
           echo anchor('welcome/view_album/'.$album['id'],img(array('src' => $this->get_album_cover($album['cover_photo']),'alt' => $album['name'])));
           echo $album['name'];
           echo br();
        }
    }
   // view single album pics
    public function view_album($album_id=false) {
       
        if(!$album_id) show_404();
       
        $photos = $this->facebook->api($album_id.'?fields=photos');
        foreach($photos['photos']['data'] as $photo) {
            echo img(array('src' => $photo['source']));
        }
    }
   // get album cover pic 
    public function get_album_cover($cover_id) {
        $cover_pic = $this->facebook->api($cover_id);
        return $cover_pic['source'];
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
0 0 votes
Article Rating
Subscribe
Notify of
guest

3 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments