How To Display Facebook Page Photo Albums on Website Using PHP?

Before we start coding, you might be someone NOT interested in coding. If that's the case, you should use a website plugin like SociableKIT. Watch the following video.

Need to embed a single Facebook page photo album on your website? Watch this tutorial.

What's next? You can try SociableKIT now, view a live demo here and here or continue with the code tutorial below.

Let's code!

Do you have a photo manager on your website? Do you upload photos on your Facebook page as well?

If your answer is both YES, you're wasting a lot of time managing your brand's photos online.

What if there's a way to upload your photo albums ONCE, and then let it appear both on your Website and Facebook page?

Will you be happy saving your precious time?

Our code for today will make you happy then, just like we are!

Today we're gonna display Facebook Page photos on your website (publicly available photos, without any kind of restrictions)!

Our source code is useful if you want your Facebook pictures to be shown in your website in a synchronized way.

Once you uploaded an image in your fan page, it will be seen automatically in your website too.

This post will cover the following content:

1.0 Source Code Overview
2.0 Advantages and Risks
3.0 Source Code Output
4.0 Get your page access token
5.0 Create index.php with Basic HTML Code
6.0 Build and Decode Photo Albums JSON link
7.0 Retrieve Photo Albums
8.0 Create photos.php with GET request
9.0 Basic HTML Code for photos.php
10.0 Enable Image Gallery Lightbox
11.0 Build and Decode Photos JSON link
12.0 Retrieve Photos
13.0 How to Display Likes and Comments?
14.0 What People Say About This Code?
15.0 Download Source Code
16.0 SociableKIT
17.0 What's Next?
18.0 Related Source Codes
19.0 Some Notes

Let's get started!

1.0 Source Code Overview

Today we’re going to do a code that:

1. Gets photo albums and photos of a Facebook fan page (using Facebook Graph API).

2. Display these photos to a webpage (assuming it is your website) beautifully with Bootstrap. It is also responsive so it's one advantage for mobile devices. If you're not yet familiar with this awesome front-end framework, see our step by step Bootstrap tutorial here.

3. Use Bootstrap Image Gallery extension to make awesome image pop up presentation. This extension is fully responsive and touch enabled. Good for every mobile device!

2.0 Advantages and Risks

This technique has the following advantages and risks.

2.1 Advantages

  1. You save server disk space because the photos don't reside in your hosting provider.
  2. You got instant photo manager which Facebook photos. It become's awesome and new features are added frequently.
  3. You save bandwidth since the photos shown in your website are loaded from Facebook’s repository.
  4. Please add your comment if you know other advantages.

2.2 Risks

  1. When Facebook is down, your website with this feature will be down as well. But I almost never encounter Facebook was down.
  2. Facebook is not responsible if you lost your data or any disruptions on it Read section 16.3 of their legal terms.
  3. Please add your comment if you know other disadvantages or risks.

3.0 Display Facebook Photos on Website - Output

It is important to know where we are going. The output of our step by step code tutorial will look like the the BASIC source code. See output preview below.

3.1 BASIC Source Code - Output Preview


3.2 PRO Source Code - Output Preview


The PRO source code outputs proves that you can add and customize more features. It’s easier and faster if you will learn by following our tutorial below.

Downloading our source codes is your huge advantage as well. For now, let’s proceed to the step by step tutorial of our BASIC source code. Enjoy!

4.0 Get your page access token

Before you can get any data from your Facebook page via the graph API, you need a "page" access token.

Follow this detailed tutorial about how to get a page access token: How to get a Facebook page access token?

Replace YOUR_ACCESS_TOKEN with your page access token.

5.0 Create index.php with Basic HTML Code

Create index.php and with the following basic HTML code.

<?php
$page_title = "Photo Albums";
?>
<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title><?php echo $page_title; ?></title>

    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
	<style>
	.col-md-4{
		margin: 0 0 2em 0;
	}
	</style>
</head>
<body>

<div class="container">

</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

</body>
</html>

6.0 Build and Decode Photo Albums JSON link

Inside the DIV with a "container" class, put the page title, specify the Facebook page ID and decode the JSON string from a graph API URL.

<?php

echo "<div class='col-lg-12'>";
	echo "<h1 class='page-header'>{$page_title}</h1>";
echo "</div>";

$access_token="YOUR_ACCESS_TOKEN";

$fields="id,name,description,link,cover_photo,count";
$fb_page_id = "221167777906963";

$json_link = "https://graph.facebook.com/v2.8/{$fb_page_id}/albums?fields={$fields}&access_token={$access_token}";
$json = file_get_contents($json_link);

$obj = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);

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

7.0 Retrieve Photo Albums

Loop through the retrieved content. Put the following code under $album_count variable on step 2 above. It links to another PHP file called photos.php where the user can view the photos inside the album.

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

	$id = isset($obj['data'][$x]['id']) ? $obj['data'][$x]['id'] : "";
	$name = isset($obj['data'][$x]['name']) ? $obj['data'][$x]['name'] : "";
	$url_name=urlencode($name);
	$description = isset($obj['data'][$x]['description']) ? $obj['data'][$x]['description'] : "";
	$link = isset($obj['data'][$x]['link']) ? $obj['data'][$x]['link'] : "";

	$cover_photo = isset($obj['data'][$x]['cover_photo']['id']) ? $obj['data'][$x]['cover_photo']['id'] : "";

	// use this for older access tokens:
	// $cover_photo = isset($obj['data'][$x]['cover_photo']) ? $obj['data'][$x]['cover_photo'] : "";
	
	$count = isset($obj['data'][$x]['count']) ? $obj['data'][$x]['count'] : "";

	// if you want to exclude an album, just add the name on the if statement
	if(
		$name!="Profile Pictures" &&
		$name!="Cover Photos" &&
		$name!="Timeline Photos"
	){

		$show_pictures_link = "photos.php?album_id={$id}&album_name={$name}";

		echo "<div class='col-md-4'>";
			echo "<a href='{$show_pictures_link}'>";
				echo "<img class='img-responsive' src='https://graph.facebook.com/v2.3/{$cover_photo}/picture?access_token={$access_token}' alt=''>";
			echo "</a>";
			echo "<h3>";
				echo "<a href='{$show_pictures_link}'>{$name}</a>";
			echo "</h3>";

			$count_text="Photo";
			if($count>1){ $count_text="Photos"; }

			echo "<p>";
				echo "<div style='color:#888;'>{$count} {$count_text} / <a href='{$link}' target='_blank'>View on Facebook</a></div>";
				echo $description;
			echo "</p>";
		echo "</div>";
	}
}

8.0 Create photos.php with GET request

Create photos.php with the following PHP code the retrieves value from a GET request. We'll get the album ID and Name that can be used to the page title.

<?php
$album_id = isset($_GET['album_id']) ? $_GET['album_id'] : die('Album ID not specified.');
$album_name = isset($_GET['album_name']) ? $_GET['album_name'] : die('Album name not specified.');

$page_title = "{$album_name} Photos";
?>

9.0 Basic HTML Code for photos.php

Under the code on step 4 above, put the following basic HTML code.

<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title><?php echo $page_title; ?></title>

    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

</head>
<body>

<div class="container">

</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

</body>
</html>

10.0 Enable Image Gallery Lightbox

We'll include the Blueimp gallery extension so we can view our photos beautifully. Our basic HTML code will look like the following code.

<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title><?php echo $page_title; ?></title>

    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

	<!-- blue imp gallery -->
	<link rel="stylesheet" href="http://blueimp.github.io/Gallery/css/blueimp-gallery.min.css">
	<link rel="stylesheet" href="Bootstrap-Image-Gallery-3.1.1/css/bootstrap-image-gallery.min.css">

	<style>
	.photo-thumb{
		width:214px;
		height:214px;
		float:left;
		border: thin solid #d1d1d1;
		margin:0 1em 1em 0;
	}

	div#blueimp-gallery div.modal {
		overflow: visible;
	}
	</style>
</head>
<body>

<div class="container">

</div>

<!-- The Bootstrap Image Gallery lightbox, should be a child element of the document body -->
<div id="blueimp-gallery" class="blueimp-gallery">
    <!-- The container for the modal slides -->
    <div class="slides"></div>
    <!-- Controls for the borderless lightbox -->
    <h3 class="title"></h3>
    <a class="prev">‹</a>
    <a class="next">›</a>
    <a class="close">×</a>
    <a class="play-pause"></a>
    <ol class="indicator"></ol>
    <!-- The modal dialog, which will be used to wrap the lightbox content -->
    <div class="modal fade">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" aria-hidden="true">&times;</button>
                    <h4 class="modal-title"></h4>
                </div>
                <div class="modal-body next"></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left prev">
                        <i class="glyphicon glyphicon-chevron-left"></i>
                        Previous
                    </button>
                    <button type="button" class="btn btn-primary next">
                        Next
                        <i class="glyphicon glyphicon-chevron-right"></i>
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

<script src="http://blueimp.github.io/Gallery/js/jquery.blueimp-gallery.min.js"></script>
<script src="Bootstrap-Image-Gallery-3.1.1/js/bootstrap-image-gallery.min.js"></script>

<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

<!-- to make photos full view -->
<script>
$('#blueimp-gallery').data('useBootstrapModal', false);
$('#blueimp-gallery').toggleClass('blueimp-gallery-controls', true);
</script>

</body>
</html>

11.0 Build and Decode Photos JSON link

Inside the DIV tag with a "container" class, put the page title HTML, specify the JSON url and decode the JSON string.

<?php
echo "<h1 class='page-header'>";
	echo "<a href='index.php'>Albums</a> / {$page_title}";
echo "</h1>";

$access_token="your access token";
$json_link = "https://graph.facebook.com/v2.3/{$album_id}/photos?fields=source,images,name&access_token={$access_token}";
$json = file_get_contents($json_link);

$obj = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);

$photo_count = count($obj['data']);
?>

12.0 Retrieve Photos

After the $photo_count variable on the code above, loop through the values using the code below:

for($x=0; $x<$photo_count; $x++){

	// $source = isset($obj['data'][$x]['source']) ? $obj['data'][$x]['source'] : "";
	$source = isset($obj['data'][$x]['images'][0]['source']) ? $obj['data'][$x]['images'][0]['source'] : ""; //hd image
	$name = isset($obj['data'][$x]['name']) ? $obj['data'][$x]['name'] : "";

	echo "<a href='{$source}' data-gallery>";
		echo "<div class='photo-thumb' style='background: url({$source}) 50% 50% no-repeat;'>";

		echo "</div>";
	echo "</a>";

}

13.0 How to Display Likes and Comments?

The feature of displaying number of likes and comments and actual comments are now included in our PRO source code. Checkout the live demo of our PRO source code above in section 3.2

14.0 What People Say About This Code?

I’m so glad that other people are delighted by this code, here are some of them!

★★★★★ "The code works beautifully. I had no problems... Great code. DONATE TO THIS SITE!" ~ jdogfantastic

★★★★★ "Ninja Mike, this wonderful tutorial has allowed me to do something totally over my head. Thank you!" ~ Handy

★★★★★ "Hey this is a great and useful script! I've managed to change some stuff around as I wanted to show photos from a specific album..." ~ Konstantinos

★★★★★ "Hi Mike, this is really... really... great work dude. You really helped me out today. I added my own twist of incorporating it into AJAX as well. I will post my version of the code." ~ Paul

★★★★★ "THANK YOU SO MUCH! I've been searching and struggling to create a new way for my web customers to organize their own photos on their websites, and this is perfect!!!" ~ Little Doe

★★★★★ "Hi, I"m doing a website for an NGO that helps cancer patients and I've used part of your script to display Facebook photos. Great work, btw." ~ Will

★★★★★ "Hi Mr. Dalisay, My name is Clinton and I'm a front-end designer. I purchased two scripts from you today. Thank you for your time and what a great tutorial and was happy to support your projects." ~ Clinton

★★★★★ "Thanks for the excellent support..." ~ Horatio

15.0 Download Source Code

You can get the source code by following the whole, step by step tutorial above. But isn’t it more convenient if you can just download the complete source code we used, and play around it?

There’s a small fee in getting the complete source code, it is small compared to the value and skill upgrade it can bring you, or income you can get from your website project or business.

For a limited time only, I will give you the source code for a low price. Download the source code by clicking the green buy button below.

15.1 Download BASIC Source Code

FEATURES BASIC
Manage photos on your Facebook page and website only once Yes
Save time figuring out and coding these features on your website Yes
Display list of photo albums Yes
Display album cover Yes
Display album description Yes
Display number of photos inside an album Yes
Link to actual Facebook album page (opens in new tab) Yes
Clicking a photo album will show list of photos Yes
Each photo are in a square thumbnail Yes
Clicking a photo will pop a lightbox Yes
Navigate photos using the lightbox's Next and Prev buttons Yes
Responsive photo albums page Yes
Responsive photos page Yes
Responsive lightbox pop up window Yes
Touch-enabled lighbox gallery (great for smartphone and tablet devices) Yes
Bootstrap UI enabled Yes
Free source code updates. Yes
Free email support for 6 months. Yes
Download Now

THANK YOU!

has been added to your cart!

Powered by Easy Digital Downloads

Thank you!

have been added to your cart!

Powered by Easy Digital Downloads

15.2 Download PRO Source Code

FEATURES PRO
All features of the BASIC source code Yes
Can show more than 25 photo albums Yes
Can show more than 25 photos Yes
Load more photo albums automatically when scrolling Yes
Load more photos automatically when scrolling Yes
Will say "All photo albums were loaded." if no albums to be shown. Yes
Will say "All photos were loaded." if no photos to be shown. Yes
Photo album cover automatically cropped to certain size Yes
No need to make each photo album cover the same size Yes
Font awesome icons Yes
Share buttons on photos page Yes
Object-oriented programming YES
Display comments of photo albums YES
Load more comments of photo albums YES
Display comments of photos YES
Load more comments of photos YES
Count number of comments of each person YES
Display image comments YES
Useful variables you can change in /libs/php/dsm_facebook_photos.php
$fb_graph_api_version
to easily change Facebook Graph API version.
YES
$limit
to easily change default number of photo albums and photos shown
YES
$hidden_albums
to easily hide photo albums.
YES
$access_token
to easily change to your own access token
YES
How to display PHOTO ALBUMS using the PRO source code?
1. Once you extracted the files,
copy the folder 'display-facebook-photos-pro' in your root directory.
YES
2. Put the following code at the beginning of you PHP file.

include_once 
"display-facebook-photos-pro/libs/php/dsm_facebook_photos.php";
$dsm_facebook_photos = new DsmFacebookPhotos();
YES
3. Put the following code inside head section.

echo $dsm_facebook_photos->printCSS_DsmPhotoAlbums();
YES
4. Put the following code where you want the feed to appear.

echo $dsm_facebook_photos->readPhotoAlbums_Dsm();
YES
5. Put the following code before the closing body tag.

echo $dsm_facebook_photos->printJavaScript_DsmPhotoAlbums();
YES
How to display PHOTOS using the PRO source code?
1. Once you extracted the files,
copy the folder 'display-facebook-photos-pro' in your root directory.
YES
2. Put the following code at the beginning of you PHP file.

include_once 
"display-facebook-photos-pro/libs/php/dsm_facebook_photos.php";
$dsm_facebook_photos = new DsmFacebookPhotos();
YES
3. Get parameter values. Put the following code next.

$album_id = isset($_GET['album_id']) ? $_GET['album_id'] 
            : die('Album ID not specified.');
$fb_page_id = isset($_GET['fb_page_id']) ? $_GET['fb_page_id'] 
            : "221167777906963";
YES
4. Set parameter values as properties. Put the following code next.

$dsm_facebook_photos->album_id=$album_id;
$dsm_facebook_photos->fb_page_id=$fb_page_id;
YES
5. Get album details. Put the following code next.

$album_details=$dsm_facebook_photos->readAlbumDetails_Dsm();
YES
6. Set page title. Put the following code next.

$page_title = "{$album_details['name']}";
YES
7. Put page title inside title tags.

<?php echo $page_title; ?>
YES
8. Put the following before the closing head tag.

echo $dsm_facebook_photos->printCSS_DsmPhotos();
YES
9. Display photos inside album.
Put the following code anywhere in the body.

echo $dsm_facebook_photos->readContents_DsmFacebookPhotos();
YES
10. Put the following codes before the closing body tag.

echo $dsm_facebook_photos->printJavaScript_DsmPhotos();
YES
Download Now

THANK YOU!

has been added to your cart!

Powered by Easy Digital Downloads

Thank you!

have been added to your cart!

Powered by Easy Digital Downloads

Do you need more reasons to download it?

MORE REASONS TO DOWNLOAD IT
Buy only once, use up to 10 websites and Facebook pages! Yes
No different kind of licenses. Yes
No many different pricing schemes. Yes
No monthly or any recurring fees. Yes
No need to rely on another website to render Facebook photo albums and photos. Yes
No need for codes from other websites. Yes
You can learn more how to code, I love teaching and can give you free tips! Yes
Familiarize yourself with the Facebook Graph API. Yes
Features are constantly improving, and you get it for free. Yes
Completely customizable. Yes

15.5 Do You Want a Demo?

If you want a demo (Facebook photos) to see if this will work with your own Facebook page, please send me a message via email mike@codeofaninja.com, or via our official Facebook page!

Please provide your Facebook page URL on the message, thanks!

16.0 SociableKIT

You demanded it, we built it. A lot of people requested a website plugin version of this Facebook gallery code. Now it is available. It works no matter what website platform you use. We have tried it in WordPress, Squarespace, Wix and more.

17.0 What's Next?

Today we have learned how to show your Facebook photo albums and photos on your website.

Did you know that you can also display Facebook videos on your website?

Let us go to the next tutorial: How To Display Facebook VIDEOS on Website?

18.0 Related Source Codes

Did you know that you can also display other social media data on your website? I’ve created tutorials on them too, see the following:

Social Media Script Tutorials
Display Facebook Page EVENTS on Website
Display Facebook Page PHOTOS on Website
Display Facebook Page VIDEOS on Website
Display Facebook Page POSTS on Website
Display Instagram FEED On Your Website
Display Twitter FEED on Website
Display Google+ FEED on Website

19.0 Some Notes

#1 Found An Issue?

If you found a problem with this code, we can solve it faster via Email or FB message, please send me a message via email mike@codeofaninja.com, or via our official Facebook page!

Please be more detailed about your issue. Best if you can provide an error message and your test or page URL. Thanks!

Please feel free to comment if you have any questions, suggestions, found something wrong or want to contribute to this code.

#2 Become a true Ninja!

  • 1. Subscribe to social media scripts tutorial news and updates.
  • 2. Be updated about what works and what does not work on social media APIs.
  • 3. Be notified for any related social media API updates.
100% Privacy. We will never spam you!

#3 Thank You!

Thank you for reading our tutorial on how to display Facebook photos on website using PHP!

278 replies
  1. Anonymous
    Anonymous says:

    This is an excellent piece of work! However, one of the drawback could be speed… What about a script that replicates the Facebook archive locally?

  2. Anonymous
    Anonymous says:

    Hi Mike,

    this is great!
    question though, when i use my own App_id and App_secret my albums/pictures doesn’t show up. but when i use your App_id and my App_secret it shows your albums/pictures. what do i need to do with my facebook account? any Ideas?

  3. Mike Dalisay
    Mike Dalisay says:

    @anonymous_1: hmm i think you can use any caching techniques to do that on your server (e.g. http://memcached.org/)

    @anonymous_2: i think i didn’t post MY app_id and app_secret. can you give those ids you used?

    @singapore web design: I will post more about that on my future posts.

    thanks for you appreciation. :)

    • Jonas
      Jonas says:

      if you want to use pics from a user account you need to create login so you can authenticate that user, remeber if your albums are public like fan pages you are good to go but if you have set any type of restrictions then authentication is needed.

  4. Mike Dalisay
    Mike Dalisay says:

    Hi guys, I also tried and experimented this script with my FB profile pictures, unfortunately, I think this method is not suitable for fetching FB profile pictures. This method is only for Fan Pages.

    I could post about how to fetch your FB profile pictures. Please subscribe via RSS or email for updates. Thanks.

  5. GodDanIt
    GodDanIt says:

    Hi Mike,

    I got this working on my page and want to thank you , i’ve been searching for ways to get content from our Facebook fan page for ages!

    Maybe you can answer a question for me?…

    When I load my page the browser shows ‘connecting’ but the page is not shown until all the data has fetched from facebook. I realise there are a lot of images being pulled from my gallery so it will take time, but i’m taking about 10 – 20 seconds of inactivity.

    Would there be a way to activate the script once the page has displayed, that way i could add a pre-loader or notification so users understand there will be a delay?

    My page is http://www.thebetaspace.com if you want to see it in action. Thanks :)

  6. GodDanIt
    GodDanIt says:

    Ooooh! That looks good, i’ll have a bash at it
    and see what happens! :D

    Seriously, I can’t thank you enough for the original script, and your quick resonse to my question too. Cheers :)

  7. geenidee
    geenidee says:

    Hi i got an error opening index.php.

    What did i do wrong?

    Fatal error: Uncaught CurlException: 6: name lookup timed out thrown in /var/www/vhosts/socialmediamove.nl/httpdocs/ht/fb-sdk/src/facebook.php on line 622

  8. geenidee
    geenidee says:

    I enabled curl in the ini file, however, i still get the same message.

    Fatal error: Uncaught CurlException: 6: name lookup timed out thrown in /var/www/vhosts/socialmediamove.nl/httpdocs/ht/events/fb-sdk/src/facebook.php on line 622

    What am i doing wrong?

  9. Mike Dalisay
    Mike Dalisay says:

    I think your server has some issues, it is not given enough time to connect with facebook server. Try to modify your facebook.php with your editor, and find this code (probably line 89)

    public static $CURL_OPTS = array(
    CURLOPT_CONNECTTIMEOUT => 10,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 60,
    CURLOPT_USERAGENT => ‘facebook-php-2.0’,
    );

    Modify CURLOPT_CONNECTION to increase its value to, 30 or higher.

    CURLOPT_CONNECTTIMEOUT => 30,

  10. Itai
    Itai says:

    Hi this looks just like what I need for my website.However I’m getting this error:

    Fatal error: Uncaught Exception: 190: Invalid OAuth access token signature. thrown in C:wampwwwfb-sdksrcbase_facebook.php on line 668

    Any ideas why?

  11. Itai
    Itai says:

    Hi, me again :) The large photos in the script are 720px wide as in facebook’s photo display page. Is it possible to show instead the high resolution version of the image (the one available by clicking ‘download’ on facebook)?

  12. Anonymous
    Anonymous says:

    This works awesome…however is there a way to do the same with a profile not a fan page?

    There would be a tremendous amount of interest if that can be done

    Mark

  13. Checker
    Checker says:

    Hello,

    I go on the “download” button, but then I cant download the package.
    Do I miss something?
    Which files do I need to downlad?

    This is an awesome script BTW.

  14. Anonymous
    Anonymous says:

    I keep getting this error – i called my host and CURL is enabled

    syntax error, unexpected T_NEW in /homepages/6/d126613682/htdocs/drink/gallery/facebookpix/fb-sdk/src/facebook.php on line 4

  15. Mike Dalisay
    Mike Dalisay says:

    @Anonymous: I’m afraid but I don’t have any idea on that error, sorry

    @JP: I think yes, you have to select all album ids first then loop through the photos table echoing all photos from those album ids.

    @arcadio813: I think its a yes too, you just have to get the ids of your fb page albums then use those ids to query your albums. something like multiple: …WHERE aid = ‘your_album_id’, other way would be: …WHERE aid IN( ‘album_id_1’, ‘album_id_2’, ‘album_id_3’)

    @Anonymous: could you post your query on selecting images and the link to your fan page? hmmm maybe you uploaded duplicate images on your fan page and that was fetched by our script

  16. JP
    JP says:

    Thanks for the reply Mike. Anonymous is me too btw, forgot to use the name/url option. Sorry for the confusion.

    Anyway, here’s the query I used:

    “SELECT pid, aid, owner, src, src_big, src_small, link, caption, created FROM photo WHERE aid IN (SELECT aid FROM album WHERE owner = 205702516132944) ORDER BY created DESC”

    I used the COAN dummy page as per the demo to test it out.

  17. Anonymous
    Anonymous says:

    Hello Mike!

    Seems to be pretty simple. I would try out with your App ID before starting with mine. But I got an error (Fatal error: Uncaught Exception: 190: Invalid OAuth access token signature. thrown in /home/antimon/public_html/beta/fb-test/fb-sdk/src/facebook.php on line 515). I have just uploaded your full package here, without no changes: http://beta.anti-monkey.com/fb-test/. Any idea what could went wrong?

    thanx :)

  18. Anonymous
    Anonymous says:

    hei, i have problem like:

    Fatal error: Uncaught exception ‘Exception’ with message ‘Facebook needs the CURL PHP extension.’ in /var/www/fesbuklike/sdk/src/base_facebook.php:19 Stack trace: #0 /var/www/fesbuklike/sdk/src/facebook.php(18): require_once() #1 /var/www/fesbuklike/gallery.php(11): require(‘/var/www/fesbuk…’) #2 {main} thrown in /var/www/fesbuklike/sdk/src/base_facebook.php on line 19

    tell us what problem this like??

    thx.

  19. hkysk8r86
    hkysk8r86 says:

    is there a way to also pull the LIKE and SHARE buttons as well from a given photo/album as well? Just curious as it’d be more beneficial to not have to take a person away from my site in order to use the social aspects of a facebook album.

  20. stefano
    stefano says:

    Fantastic script!!!!!!
    I was going crazy to find a method to display in my website the facebook pics!
    But..i have one question..can i show also albums of people or group? how do i?

  21. Tosin Orojinmi
    Tosin Orojinmi says:

    hello Mike,

    great work. though i have not seen it at work

    i have this error:

    Fatal error: Uncaught Exception: 102: Session key invalid or no longer valid thrown in C:wampwwwomafoundationphp-sdkbase_facebook.php on line 1039

  22. Anonymous
    Anonymous says:

    Hi I’m trying to get a loading bar working and used the code from your paginating data tutorial as you suggested in a comment in july. It works on the initial page load, but if you click an album it reloads the whole page instead of opening the album. Any ideas to get around this???

  23. Anonymous
    Anonymous says:

    Hi Mike,
    Thank you for all the extremely helpful posts you have written and initiated.
    I am struggling with my first facebook app and your code is very helpful though …
    I can’t access my albums, with my app id and secret id I can view your and funky cakes albums but using my owner id: 100002604335685
    I receive the error “Fatal error: Uncaught Exception: 102: Session key invalid or no longer valid thrown in “.
    I haev made my albums public is there something else that I am missing that you cann see?
    Much appreciated,
    Moz

  24. Metacowboy
    Metacowboy says:

    Very nice work mike it helps to build a Media RSS feed hope it gets the video url int he album too that would be over hit
    should work with public groups ?

    Thank you very much

  25. Manuel
    Manuel says:

    Hi Mike,
    This is an awesome script, if I only can get it to work!!!!
    I’m using wysiwyg to do my webpage and I’m using jQuery to make a photoalbum thats on my server how ever when I’m trying to use your script as is just to see if it works i get the following error:
    Fatal error: Uncaught Exception: 190: Invalid OAuth access token signature. thrown in D:Hosting6940775htmlFotoalbumFacebookfb-sdksrcfacebook.php on line 515
    I have 2 problems, one I’m not a programer I’m a golfpro and I have up to now put a link to the facebook pictures on my webpage, but this is very timeconsuming and requieres constant updates of the webpage. It’s so easy just to upload pictures directly to facebook but there is where my second problem comes, most of my clients are 60+ and they dont have facebook. I’m desperate for help and I would be more than happy to pay to get this solved as it is very important to me and my company.
    Sincerely,
    Manuel.

  26. elgordo
    elgordo says:

    It is possible to get the photos of users whom you are friends with. Add the following lines before the line

    // defining action index
    if ($facebook->getSession()) {
    echo “You have a facebook session for this app”;
    } else {
    echo “You need to login first – “;
    echo ‘Login‘;
    }

    Whatever URL you are using for testing, this needs to be added in the Website section of the facebook application settings. AAfter clicking on Login, your browser will be redirected back to the same page, upon which the login button now disappears as you are logged into facebook with respect to the application.

    Then change your search to the id of the user whom you are interested in. There is no longer a restriction to just pages

  27. Nias
    Nias says:

    Hi, I have a problem, i download file Fb-SDK/src/facebook.php and upload to my localhost to folder “fb-sdk/src/facebook.php”. I start /localhost and select folder in browser and browser wrote message error “Parse error: syntax error, unexpected ‘]’ in C:ComplexWebServerhttp_docsjfb-sdksrcfacebook.php on line 940”. Whre is problems?

    Script from 940 line: hashComments:b,cStyleComments:b,multiLineStrings:b,regexLiterals:b}),B={};h(da,[“default-code”]);h(y([],[[“pln”,/^[^]*(?:>|$)/],[“com”,/^<!–[sS]*?(?:–>|$)/],[“lang-“,/^<?([sS]+?)(?:?>|$)/],[“lang-“,/^<%([sS]+?)(?:%>|$)/],[“pun”,/^(?:<[%?]|[%?]>)/],[“lang-“,/^]*>([sS]+?)</xmpb[^>]*>/i],[“lang-js”,/^]*>([sS]*?)(</scriptb[^>]*>)/i],[“lang-css”,/^]*>([sS]*?)(</styleb[^>]*>)/i],[“lang-in.tag”,/^(</?[a-z][^<>]*>)/i]]),”default-markup,htm,html,mxml,xhtml,xml,xsl”.split(“,”));
    Where is a problem/s? Can you help me pls ? Thank!

  28. pixelneer
    pixelneer says:

    Hey Mike, thanks for the great script.

    I have it implemented, and I can plug in just about any facebook id to get their feed, except the one I am trying to get. Is there something in particular I need to do to the feed on facebook’s end to ensure it shows up?

    Any help is greatly appreciated.

    Here is the page I’m trying to put it on:
    http://dev.bigshift.com/music-iframe/

    with this ID:167626859995709

    Thanks.

  29. Rathan Kalluri
    Rathan Kalluri says:

    Hey Mike..thats a great piece of code ..i made a small implementation of it here..

    http://goo.gl/Ti6yo

    thats just for a sample..

    and Mike the issue i have is with the thumbnails.. can’t I get all the thumbnails in one size.. ‘coz they look a bit unnatural when they are of different sizes..

    Please Help me out . Thanks in advance …

    Rathan

  30. Anonymous
    Anonymous says:

    Hi Mike, thanks for all your hard work. I’m searching for a way for group members on FB to be able to post a public album to the group and allow other members (non-friends) to be able to tag or comment on the photos in the album. Members can post an album, but cannot comment on the photos. Any suggestions? Here’s a link to one of my public albums so that you can see what I mean… https://www.facebook.com/media/set/?set=a.10150789080685968.499526.781045967&type=3&l=2defbbcec4

    Thanks for any suggestions!
    Cheryl

  31. patrick
    patrick says:

    Hello! love the script, however I am getting phantom albums that are being created. If i create a new album in facebook & upload 1 picture, it displays in the script normally. However, if I have more than one picture, your script creates a phantom album with the same cover photo, but it’s labeled untitled & has no pictures in it… any advice?

    • patrick
      patrick says:

      I followed your code exactly and don’t have any errors, aside from this one… it’s really bugging me. The only thing I can think of is that possibly it’s an issue with facebook? As this only happens with my newer albums, and not the older ones.

      Do you have any idea as to why this is occurring Mike?

      If you take a look at the demo, it’s generating two untitled albums, with no pictures in them… advice?

  32. jdogfantastic
    jdogfantastic says:

    The code works beautifully. I had no problems except for one. When I uploaded it and changed out the APP ID and Secret everything was working. I located the facebook Page ID and swapped it out too. Everything was fine till I clicked on an album. “File not found” Turns out that renaming your file “index.php” will render the program unusable unless you fix line 53 ( echo”<div><a href=”RENAMEDFILE” . . ) Works now. Great Code. DONATE TO THIS SITE!

  33. Paul
    Paul says:

    Hi Mike, this is really… really… great work dude. You really helped me out today. I added my own twist of incorporating it into ajax as well. I will post my version of the code. However I am having the same problem as two other people who commented here. The problem also existed when using the original form of your code without the ajax.

    …it’s the phantom albums. I have several blank albums showing up and it’s really annoying. See under the gallery section @ http://www.havanahookah.net/index2.php

    thanks in advance…
    Paul

    • Paul Zmuda
      Paul Zmuda says:

      Part 2 ;)

      photos.php =
      ||||div style=’font-size: 16px; font-weight: bold; margin: 0 0 10px 0; color: #FFF;’>
      This album is synchronized with the Havana Hookah
      ||||a href=’https://www.facebook.com/HavanaHookahLounge/photos’ target=”_blank”>
      Facebook Photo Album.
      ||||/a>
      ||||/div>

      ||||?php
      //include the facebook PHP SDK
      require ($_SERVER[‘DOCUMENT_ROOT’].’/fb-sdk/src/facebook.php’);

      $facebook = new Facebook(array(
      ‘appId’ => ‘ENTER YOUR OWN APPID’,
      ‘secret’ => ‘ENTER YOUR APP SECRET’,
      ‘cookie’ => true, // enable optional cookie support
      ));

      //defining action index
      isset( $_REQUEST[‘action’] ) ? $action = $_REQUEST[‘action’] : $action = “”;

      //if there’s no action requested
      if( $action == ”){
      echo “”;

      $fql = “SELECT aid, cover_pid, name FROM album WHERE owner=########### AND name != ‘November 22, 2011’ AND name != ‘November 17, 2011’ AND name != ‘November 16, 2011’ AND name != ‘SEPT 11 2011’ AND name != ‘NORRIDGE TOBACCO HALLOWEEN PARTY OCTOBER 29 2011′”;
      $param = array(
      ‘method’ => ‘fql.query’,
      ‘query’ => $fql,
      ‘callback’ => ”
      );
      $fqlResult = $facebook->api($param);
      echo “||||div class=’galcenter’>”;
      foreach( $fqlResult as $keys => $values ){

      //we will do another query
      //to get album cover
      $fql2 = “select src from photo where pid = ‘” . $values[‘cover_pid’] . “‘”;
      $param2 = array(
      ‘method’ => ‘fql.query’,
      ‘query’ => $fql2,
      ‘callback’ => ”
      );
      $fqlResult2 = $facebook->api($param2);
      foreach( $fqlResult2 as $keys2 => $values2){
      $album_cover = $values2[‘src’];
      }
      echo “||||div style=’padding: 10px; width: 150px; height: 170px; float: left; color: #FFF;’>”;
      echo “||||a onclick=’fetchAlbum(“” . $values[‘aid’] . “”, “” . $values[‘name’] . “”)’ style=’cursor: pointer; ‘>”;
      echo “||||img src=’$album_cover’ border=’1′>”;
      echo “||||/a>||||br />”;
      echo $values[‘name’];
      echo “||||/div>”;

      }
      echo “||||/div>”;
      }

      //when the user clicked an album
      //it will show or list all the pictures
      //on that album
      if( $action == ‘list_pics’){
      isset( $_GET[‘name’] ) ? $album_name = $_GET[‘name’] : $album_name = “”;

      echo “||||div style=’color: #FFF;’>||||span style=’cursor: pointer; text-decoration: underline; color:#0033FF;’>||||a onclick=”loadPage(‘photos’)”>Back To Albums||||/a>||||/span> | Album Name: ||||b>” . $album_name . “||||/b>||||/div>||||br />”;
      echo “||||script language=javascript>scroll(0,0);||||/script>”;
      $fql = “SELECT pid, src, src_small, src_big, caption FROM photo WHERE aid = ‘” . $_REQUEST[‘aid’] .”‘ ORDER BY created DESC”;
      $param = array(
      ‘method’ => ‘fql.query’,
      ‘query’ => $fql,
      ‘callback’ => ”
      );
      $fqlResult = $facebook->api($param);

    • Paul Zmuda
      Paul Zmuda says:

      Part 3 :o

      //so that jQuery lightbox will pop up
      //once the image was clicked
      echo “||||div id=’gallery’ class=’galcenter’>”;

      foreach( $fqlResult as $keys => $values ){

      if( $values[‘caption’] == ” ){
      $caption = “”;
      }else{
      $caption = $values[‘caption’];
      }

      echo “||||div style=’padding: 10px; width: 150px; height: 170px; float: left;’>”;
      echo “||||a href=”” . $values[‘src_big’] . “” title=”” . $caption . “”>”;
      echo “||||img src='” . $values[‘src’] . “‘ style=’border: medium solid #ffffff;’ />”;
      echo “||||/a>”;
      echo “||||/div>”;
      }

      echo “||||/div>”;
      }
      ?>

      ||||!– jQuery lightbox include script –>

      ||||script type=”text/javascript” src=”../jQuery-lightbox/js/jquery.js”>||||/script>
      ||||script type=”text/javascript” src=”../jQuery-lightbox/js/jquery.lightbox-0.5.js”>||||/script>
      ||||link rel=”stylesheet” type=”text/css” href=”../jQuery-lightbox/css/jquery.lightbox-0.5.css” media=”screen” />

      ||||!– END JLIGHTBOX –>
      ||||script type=”text/javascript”>
      $(function() {
      $(‘#gallery a’).lightBox();
      });
      ||||/script>

      …I hope this helps. Sorry if this is all over the place, I did it over a month ago and I just retraced my steps to try and reply with something. It’s not perfect but does the job as needed right now. I never got an email notifying me of your response or I wouldve replied back in April. I feel I owe the author of this tutorial that much :)

  34. Paul
    Paul says:

    Nevermind I used your suggestion to filter out 4 phantom albums. What I think this is could be deleted albums still in facebook’s fql databse???? Some of the titles seemed like older, and crappier names to existing albums. I’ll ask the original owner of the fan page as im doing this for somebody. Maybe there’s an extra column to filter out in the fql query like “status != deleted” or something… who knows maybe a bug? If you could try in your own demo, delete and recreate an album and see what shows up?? Ill try this on my own time but it wont be any time soon. Thanks again dude!

    • Mike Dalisay
      Mike Dalisay says:

      Hi Paul, I’m glad it works for you. I haven’t looked at that instance yet (I may find time), but maybe, the deleted albums isn’t instantly deleted on facebook’s servers. It might take some time before it will be completely removed. Anyway, what is important now is you can filter out what albums must be shown on your client’s site. :)

  35. Chris
    Chris says:

    Great code!
    I’ve modified it to load individual facebook pages (as in your personal one) but I’m encountering an issue where if the page fully loads the clicked album isn’t visible, but if you press it before its finished loading it works fine. Any help/tips?

    http://www.xkarlbriggsx.co.uk/gallery.php it links to the facebook app, requires authorisation, loads the photos from the users gallery, but as mentioned stops being clickable once its loaded!

  36. Anonymous
    Anonymous says:

    Where should my facebook appID link to?? I have tried my facebook landing page appID and secret code that doesnt seem to work. My question is when i create an appID where should i reference it to?

  37. Little Doe Design
    Little Doe Design says:

    GOT IT!

    So replace line 28 (this line: $fql = “SELECT aid, cover_pid, name FROM album WHERE owner=188166104626524”;)

    WITH THIS:

    $fql = “SELECT aid, cover_pid, name FROM album WHERE owner=188166104626524 AND name<>’Wall Photos’ AND name<>’Cover Photos’ AND name<>’Profile Pictures'”;

  38. Steve189
    Steve189 says:

    I had this code working fine on a site, thanks for providing it. But, now the gallery section on the site is just blank. I’ve checked the facebook page owner hasn’t deleted their albums. Puzzled. Has anyone else using this reported similar problems?

  39. Daniel Ilicic
    Daniel Ilicic says:

    Hi there, i have to tell you that something is wrong with this code, at first everithing was working just fine, but for several days in my gallery thumbnails of album is not showing. I have went to your page, see where have I mistaken, and on your demo that doesnt work either.. so, did facebook changed something or what is happening?

    Daniel

  40. Anonymous
    Anonymous says:

    jQuery NOOB needs assistance.

    Hi~ I’m working on a site for a non-profit animal rescue and I’m hoping to use your script to pull in pics from our FB page (http://facebook.com/LilOrphanHammies )

    The page I would like them to pull to is: http://lilorphanhammies.org/scrapbook

    I have not yet integrated Lightbox, but I got the impression from everything above that this is the “icing on the cake” as opposed to a mandatory item for function.

    I’ve entered our App ID and Secret. Can anyone tell me what I’m missing/ doing wrong?

    Thank you!

  41. Greglim
    Greglim says:

    I want to go to an album and display on my website only the one(s) I click not all, how this code will vary. What I can not do is retrieve the id of one clicked (selected) photo.
    Thanks

  42. fai
    fai says:

    Hi Mike
    is it possible to display the like button beside the photo ? I was taking to add the like_count in the FQL , doesnt work. I am trying to add a poll photo by like on my webpage.
    Thanks ,,
    looking forward to your voice
    fai

  43. Steve189
    Steve189 says:

    Still not working for me either :( it was working perfectly to begin with. I didn’t alter a thing but suddenly, no photos. I’ve also created a new FB app and tried that but still, nada.

  44. Kevin
    Kevin says:

    Hey,

    I have a question. Basically if you have a show_photos page with say 3 pages, and you click on a picture on first page and press the next button in the modal window/pop-up only the photos in the first page will be displayed.

    In other words, if you have 3 pages you cant view each picture in all of the pages via the modal popup.

    What’s the way around this?

    Thank you :)

  45. AllanC
    AllanC says:

    Hi, Thanks for your code. I successfully pulled a random members photo from our open group page. However, it takes time to load. Maybe I didnt put the right code or something. Im just an average PHP/FQL programming so bear with me.

    Here is out website: http://www.chagalog.org/

    If you could create a new tutorial on how to pull members photo from an open group page that is fast loading, that would be great!

    Thanks again

  46. Frederick Kuhrt
    Frederick Kuhrt says:

    Hi. I like that app. and wanted to include it in wordpress. It works smoothley until I click on one album. The following link will not work ..

    Example link: index.php?action=list_pics&aid=221167777906963_68635&name=Android

    So the fotos in the album aren’t shown.

    Any suggestion or experience in handling this with permalinks ..?

    Thanks
    Fred

  47. Chris
    Chris says:

    How would I modify this script to display only the photos from one album, instead of all albums?

    It works great, I just need to show photos from one album though.

    Thanks in advance.

  48. Pawan
    Pawan says:

    Hi Mike,
    Im getting fatal error at run time

    Uncaught exception ‘Exception’ with message ‘Facebook needs the CURL PHP extension.’ in C:xampphtdocsFacebook_Photofacebook.php:4 Stack trace: #0 {main} thrown in C:xampphtdocsFacebook_Photofacebook.php on line 4

  49. Sumit Kumar Kasaudhan
    Sumit Kumar Kasaudhan says:

    Hi Mike,

    I am using Pull_Facebook _data code which is given by you but don’t run it show this Error please guide me as soon as possible.
    ERROR———

    Fatal error: Uncaught CurlException: 60: SSL certificate problem, verify that the CA cert is OK. Details:
    error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
    thrown in C:xampphtdocspull-facebook-datafb-sdksrcbase_facebook.php on line 886
    ————-

    thanks

    sumit kumar

  50. simran
    simran says:

    i face some error in this code.there is error of uncaught exception .

    Fatal error: Uncaught Exception: 190: Invalid OAuth access token signature.
    thrown in C:xampphtdocssitefb-sdksrcbase_facebook.php on line 1254.
    plz give me the answer of this prob.

  51. simran
    simran says:

    i found error of

    —Fatal error: Uncaught CurlException: 60: SSL certificate problem, verify that the CA cert is OK. Details:
    error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
    thrown in C:xampphtdocssitejQuery-lightboxfb-sdksrcfacebook.php on line 622
    plz give the solution.

    • Sylvain
      Sylvain says:

      Could you please show us how you made this ?
      I’ve tried several solutions, but nothing happenned.

      It would be nice from you !

      Thanks in advance.

      • Sylvain
        Sylvain says:

        I tried to change this part
        __________________________________________
        $fql = “SELECT
        aid, cover_pid, name
        FROM
        album
        WHERE owner=151037504938143”;
        __________________________________________

        into this
        __________________________________________
        $fql = “SELECT
        pid, src, src_small, src_big, caption
        FROM
        photo
        WHERE aid=151037504938143_1073741825”;
        __________________________________________

        Does someone can help me to have it working ?

  52. David Kae
    David Kae says:

    This might be a dumb question, but if I already have an app do I have to create a new one for each of these new features? Or can I continue to use the same key and secret code for these. They are for the same website, so the URL won’t change.

  53. chris
    chris says:

    this is great. I have it working but now the facebook page I am using has a ton of pictures… is there a way to paginate the images once you open an album?

  54. Eric
    Eric says:

    Excellent script. Thanks so much. Is there a way I can link an image to take the visitor to facebook so they can tag the photo? Or allow them to tag on our web page?

  55. Mo
    Mo says:

    Hello,

    Many thanks for such an awesome script. I have been using for over a year now without any problems. However, recently, I have come across a problem, none of my albums nor images are being shown on my website. Could you please assist me when you are available to do so?

    Thank you in advance.

  56. Konstantinos MKink TattooPierc
    Konstantinos MKink TattooPierc says:

    Hey this is a great and useful script! I’ve managed to change some stuff around as I wanted to show photos from a specific Album but there is a problem. If I leave it to “ORDER BY created DESC” it returns a limited amount of photos from the album, on the other hand if you go for ASC it will return all of them, any idea how can we make a DESC but grabbing everything ? Plus i’m getting 2 errors for ‘headers already sent’, anyway possible to fix that ( i have no idea what it is ). Thanks in advance! :)

  57. Handy
    Handy says:

    Ninja Mike, This wonderful tutorial has allowed me to do something totally over my head. Thank you! Can you show an example of how to change the code to exclude certain albums, or only include select albums from the FB account?

    I am not sure what to put here:

    $fql = “SELECT
    aid, cover_pid, name
    FROM
    album
    WHERE owner=****************”;

    I have tried lots of things, but just blow it up.

  58. Rakesh Shetty
    Rakesh Shetty says:

    Hi its a nc script thank you for your code but my issue is it is working for some ownerid not for everyone why so? is that a permission issue ? if yes how can i fix this ?

  59. Mg Linn
    Mg Linn says:

    I found that some of the album have error :

    eg .
    Fatal error: Uncaught Exception: An unknown error occurred thrown in /home/mjd/public_html/mysite/fb-sdk/src/base_facebook.php on line 1340

  60. Tburton
    Tburton says:

    I Purchased pro version of this is think it should be noted more clearly; This will ONLY work with specific types of FB pages. Different pages have different permissions, these permissions effect whether or not this code will work. An example of a VALID type of page can be found in the following tutorial from this site; https://www.codeofaninja.com/2013/02/how-do-you-start-facebook-page.html

    In my case, my client created a new FB account but the page type he had selected prevented this code from running. I spent time trouble shooting and thought I’d share with anyone else that might experience the same. Typically I was seeing errors related to Tokens/permissions etc.

    • ninjazhai
      ninjazhai says:

      Hello @Tburton, sorry for the trouble but as mentioned in the source code overview, it’s for Facebook fan pages (which have publicly available data), I apologize for not mentioning it more clearly. By the way, which type of Facebook page your client did create? And what exactly the token related issue you encountered? Thanks for your time!

  61. ninjazhai
    ninjazhai says:

    Just a note if other people has the same problems, please be more detailed about your issue. Best if you can provide your test URL, FB page URL and other details. Thanks!

  62. Si
    Si says:

    Great tutorial, just what I was looking for. Can I ask though, when opening the gallery it only shows 25 images on the layout view and the pop up, despite there being more on Facebook. Is this a limitation of the basic code and is it featured in the pro version or am I missing something? Thanks!

  63. gianluca
    gianluca says:

    good evening… i have a question for you about your (the pro one that i have I bought)
    why the images are resized to 720x480px while on fb they are 2048×1366?? how is possible to have the full size image?

    thank for your help.

    Gianluca

  64. Shamma Lammadingdong
    Shamma Lammadingdong says:

    Hello- I purchased the pro version and was wondering if there was a way to load all gallery images at once rather than paging. I know the Graph API will only return 100 results at a time, hence the need for paging, but I’ve ben unsuccessful in figuring out a solution using the total number of images in the gallery vs how many have loaded thus far using javascript and php.

    I only ask as because if the user has not completely scrolled to the bottom of the page to load all the paged images, the lightbox will not show all the photos in the gallery.

    Thanks for the great script and your help!

  65. Erin Lima
    Erin Lima says:

    I bought the Pro version, but I am getting the same error I got going thru the tutorial:

    Warning: json_decode() expects at most 2 parameters, 4 given in /home/content/29/8748029/html/gallery/level-2/index.php on line 75

    Line 75 reads:
    $obj = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);

    Thanks in advance!

    • Mike Dalisay
      Mike Dalisay says:

      Erin Lima thanks for purchasing the code… I replied to you on Facebook…


      // replace this
      $obj = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);

      // for those using PHP version older than 5.4, use this instead:
      // $obj = json_decode(preg_replace('/("w+"):(d+)/', '\1:"\2"', $json), true);

  66. Temsu Lemdor
    Temsu Lemdor says:

    Been looking for a way to implement Facebook Albums integration on a website, & i gotta say, this would have to be by far the most featured plugin available that is actually working up to date with the amount of Facebook Token permissions changes that FB undertakes.
    Love the way of using Light box type load up the photos.
    cant wait to try out the entire code.
    a definite recommendation for download.

  67. Greg Thompson
    Greg Thompson says:

    My code is coming out that the cover_photo is actually an array with the data array, so it doesn’t work showing the $cover_photo because it returns “Array” instead of the ID of the cover_photo.

    “cover_photo”: {
    “created_time”: “2015-02-20T02:37:36+0000”,
    “name”: “Another good year servicing my customers”,
    “id”: “820365984665179”
    },

    • Mike Dalisay
      Mike Dalisay says:

      Hello Greg,

      Yes we noticed that the FB graph api returns different JSON string with newer access tokens. The one above will work with older access token.

      If you have a new access token, you can make it work by:

      change this:

      $cover_photo = isset($obj[‘data’][$x][‘cover_photo’]) ? $obj[‘data’][$x][‘cover_photo’] : “”;

      to this:

      $cover_photo = isset($obj[‘data’][$x][‘cover_photo’][‘id’]) ? $obj[‘data’][$x][‘cover_photo’][‘id’] : “”;

  68. Cris
    Cris says:

    HI , great code, it works great. But now i have moved to a server that they doesn’t allow file_get_contents, they have Off the allow_url_fopen for some security reasons. Is there any alternative to the file_get_contents?
    Thanks for the code.

  69. Otara Gunewardene
    Otara Gunewardene says:

    @ninjazhai:disqus
    The above tutorial gives and error,
    Parse error: syntax error, unexpected ‘221167777906963’ (T_LNUMBER) in index.php on line 33

    This error can be fixed by replacing,

    $fields=”id,name,description,link,cover_photo,count”;”;
    with,
    $fields=”id,name,description,link,cover_photo,count”;
    i guess because you have accidentally retyped (;”) at the end.

  70. quickjeff
    quickjeff says:

    @ninjazhai:disqus I have used your script before with other client sites. I have a new client site that I have setup an app for using OG 2.5 and for some reason I can load the photos but the album covers do not show. Its not the server since I can upload your stock example and everything works fine. My guess it has to do with the OG 2.5 or some permissions on my clients Business Facebook Page. Any advice would be nice!

    • quickjeff
      quickjeff says:

      Hi Mike, the site is on a dev environment that is gated. As far as the OG 2.5, its the updated Open Graph from Facebook i was referring too. You code was showing to work on 2.4.

  71. Jay
    Jay says:

    I tried the solution, it seems everything is fine but I am getting empty albums, so I tried to figure out that json is coming blank. I tried some solutions, one of them is to configure an app in facebook and give access of user_photos to that app. But it seems options are relevant to creating app to collect photos from others where as my objective is to show my own photo albums on my website. Am I going wrong?

  72. Glodson
    Glodson says:

    i found a bug, maybe caused by facebook updates:

    $json_link = “http://graph.facebook.com/v2.3/{$fb_page_id}/albums?fields={$fields}&access_token={$access_token}”;

    for sending tokens with get method you need to use the https://graph… instead of just unsecure http:// protocoll.. maybe you could change this in the tutorial…

    thanks for the tutorial anyway! gave me a good overview to use facebooks graph api. Thanks

    • Mike Dalisay
      Mike Dalisay says:

      @Glodson, thanks for telling us about this! I updated the post above with https:// and v2.8

      You’re welcome and glad our tutorial helped you with your project. Please share our site to one of your friend if you have time, thank you!

  73. Pavel Lehoucq Šípek
    Pavel Lehoucq Šípek says:

    Hi Mike :), Can I via json link download inside “$json_link = “https://graph.facebook.com/v2.8/{$album_id}/photos?fields=” also “place” of the photo?
    Thx for your support.

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.