How to display Facebook page photo albums on website using PHP?

Previously, we learned how to display Facebook page events on your website using PHP.

This tutorial will cover the steps to display Facebook page photo albums on your website using PHP. We’ll show you how to easily integrate your Facebook page’s photo albums into your website so your audience can view them without having to navigate away from your site.

By the end of this tutorial, you’ll have a seamless way to showcase your Facebook photo albums to your website visitors, keeping them engaged and up-to-date with your latest content.

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 an awesome image pop-up presentation. This extension is fully responsive and touch-enabled. Good for every mobile device!

Don’t want to code?

By the way, if you realize you do not want to code and need more features, you can use a website plugin called SociableKIT.

You can easily customize the look and feel of your Facebook page photo albums and embed them on your website within a few clicks. Following this tutorial: Embed Facebook page photo albums on website. There’s also an option to embed only one photo album on Facebook.

There’s a free plan that you can use if you don’t need the premium features of SociableKIT. But if you like coding, continue with our tutorial below!

Benefits

Use this code to enjoy the following benefits.

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

Get your page access token

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.

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>

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']);
?>

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

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

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>

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">×</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>

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']);
?>

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

}

Source code or SociableKIT?

You can choose whether to download our source code or use SociableKIT’s Facebook page photo albums widget.

FEATURESCodeSociableKIT
Manage photos on your Facebook page and website only once
Save time figuring out and coding these features on your website
Display a list of photo albums
Display album cover
Display album description
Display the number of photos inside an album
Link to an actual Facebook album page (opens in new tab)
Clicking a photo album will show a list of photos
Each photo is in a square thumbnail
Clicking a photo will pop a lightbox
Navigate photos using the lightbox’s Next and Prev buttons
Responsive photo albums page
Responsive photos page
Responsive lightbox pop-up window
Touch-enabled lightbox gallery (great for smartphone and tablet devices)
Bootstrap UI enabled
Can show more than 25 photo albums
Can show more than 25 photos inside an album
The photo album cover automatically cropped to a specific size
No need to make each photo album cover the same size
Font awesome icons
Share buttons on the photos page
No coding required
Works with any website builders like WordPress, Squarespace, or Wix
Customize colors, font, layout, texts, and more
Priority chat and email support
Lifetime support and system updates
No need to worry about Facebook API updates

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?

[adinserter block=”3″]


Comments

280 responses to “How to display Facebook page photo albums on website using PHP?”

  1. Ivan Tinonas Avatar
    Ivan Tinonas

    grabe.. imba ka .. hahaha..

  2. Thanks dude! 🙂

  3. Thx, awesome script!

  4. Anonymous Avatar
    Anonymous

    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?

  5. Anonymous Avatar
    Anonymous

    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?

    1. Remove any age or country restriction on who can view your page in facebook settings

  6. how about social graph usage?

  7. @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. 🙂

  8. Hi Mike, does this code only works if you have a photo album in a facebook page? I tried to use my ownder ID (553078968) and it doesn’t show any photo. By using yours, it works fine.
    here is the url to one of my albuns:
    http://www.facebook.com/media/set/?set=a.438311583968.209228.553078968

    any ideia to help me?

    1. 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.

  9. Great.Its working nice.Please also let us know that how can we fetch the profile album.

  10. 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.

  11. Anonymous Avatar
    Anonymous

    Hi Mike!

    Very cool stuff. Yours is the only thing like it I have found so far. Have you experimented with Events, Notes, etc? Just curious.

  12. Yes, but not yet with FB notes, be updated by subscribing to this blog. Thanks 🙂

  13. Hi Mikey, the download link give a redirect loop, and cant get to download the source files 🙁

  14. It works fine with me. But I also encountered that one time, try clearing your browser cache.

  15. Hi Mike,

    While giving your ownerid it is working .and while giving my id. It is not working. Pls clarify my dbt .

  16. 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 🙂

  17. @Siva: the owner id must be owner id of a fan page only, not profile page..

    @GodDanIt: Your welcome, I’m happy to see this script works in your page 🙂 .. hmm about the pre-loader script, maybe you could use the approach I used here http://www.codeofaninja.com/2011/06/paginating-your-data-with-ajax-and.html

  18. Ooooh! That looks good, i’ll have a bash at it
    and see what happens! 😀

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

  19. 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

  20. @geenidee: it means you have to enable Curl Extension in you php.ini file. You may google “how to enable curl in php ini” on how to do that 🙂

  21. 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?

  22. 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,

  23. it works like a charm!
    Thank you!

  24. 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?

  25. OK my bad, I forgot to enter the app ID. It works great, thank you!

  26. Glad it works for you, you’re welcome Itai! 🙂

  27. 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)?

  28. The highest image quality is given by the src_big field https://developers.facebook.com/docs/reference/fql/photo/, that’s what is already showing in our example when the jquery lightbox appear. I’m not so sure if that is also the high resolution one (the one available by clicking ‘download’ on facebook)

  29. Anonymous Avatar
    Anonymous

    Hey, nice piece of code. An important note though:

    – Your jQuery Lightbox.js file is loading images from http://calleza.com/themes/calleza/js/jquery_lightbox_and_fb/images/ (!)

  30. You’re welcome. Good catch @Anonymous! Thanks a lot for that note!

  31. Anonymous Avatar
    Anonymous

    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

  32. Hi @Mark, Unfortunately, I didn’t find a way to do this with a facebook profile… I guess facebook allow this for fan pages only.

  33. Checker Avatar
    Checker

    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.

  34. Thanks Checker, hmmm… Did you go to the menu File > Download Original? That’s on the upper left corner of the download page.

  35. Checker Avatar
    Checker

    Thank you!
    I missed that one.

    I will test the script and give feedback!

  36. Alright, good luck! 🙂

  37. Hi Mike…

    I am using all what you have said however it does not display my photos, here is the page and all it displays…

    http://funkycakes.richiesheerin.net/photos.php

    This is the owner ID I think: 236296496412576

    This is my app id & secret, appId: 184215168314424, secret: 29f9ceb9a886d9b3225c879db3ac273a

    Cheers

  38. I got it working… YEEEHA!!!

  39. @Richie: Nice one. 🙂

  40. Anonymous Avatar
    Anonymous

    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

  41. Thanks for this wonderful script, it works perfectly!

    One question though, is it possible to display all photos from all albums on a single page?

  42. Hi Mike,

    I have a couple of company pages on FB, is it possible to use your script to display single albums from these pages too, as at the moment only my albums are displayed.

    Cheers

  43. Hi Mike,

    I have a couple of company pages on FB, is it possible to display selected (with aid) albums from these pages too, as at the moment only my albums are displayed.

    Cheers

  44. Anonymous Avatar
    Anonymous

    I modified the code to display all photos from a fanpage.

    Managed to work it out,but it’s showing many duplicates of the same images. Any idea why?

  45. @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

  46. 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.

  47. Anonymous Avatar
    Anonymous

    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 🙂

  48. Anonymous Avatar
    Anonymous

    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.

    1. I know this is late but, at least for others, pleas enable CURL extension in your server. Maybe contacting your hosting company will help. 🙂

  49. 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.

  50. I’m getting the following error – Invalid or no certificate authority found, using bundled information

    please let me know what I need to do to fix this problem.

  51. 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?

  52. 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

    1. Anonymous Avatar
      Anonymous

      How u solve this 102 error Tosin? I am getting same error?
      Help me me Mike & Tosin

  53. thank you for shating the html codes I applied it thorough blogger edit html and its working …
    Vertical Jump Bible

  54. Wao!! its now working on my site, thanks.

    Any idea on how to display comment on each picture?

  55. hi mike, just wondering if your script supports video album on facebook too?

  56. http://apps.facebook.com/fbphotoextract/

    GETTING THIS
    Fatal error: Uncaught Exception: 190: Invalid OAuth access token signature. thrown in /home/socialca/public_html/facebookapplications/fbforweb/fb-sdk/src/facebook.php on line 515

  57. I am getting that same error

  58. @abhishek and @chewie41983: please check your app id and app secret.

  59. Anonymous Avatar
    Anonymous

    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???

  60. problrm 🙁 please help

  61. problem please help 🙁

  62. Thanks man…great code.. works perfectly !!!

    Cheerz,
    AJ

  63. Code is working great!

    Is there any way to display only 1 album? Basically display the page as if an album was already opened.

    I want to split up the photo albums on my website.

  64. I got it to work 😉

    Love the script dude. Should be up soon at http://www.harpersstatuary.com
    Check it out. Ill try to check this forum so I can answer some questions if needed.

    Thanks Mike for the solid programming!!

  65. Anonymous Avatar
    Anonymous

    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

  66. Metacowboy Avatar
    Metacowboy

    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

  67. Hi,
    Worked out that I needed to Create A Page rather than use my facebook account photos.
    Thanks,
    Moz

  68. hello,
    i would like to show in a jquery slider ( into a .php file for my Facebook page) images from a selected Facebook page album.
    I can’t find the solution

  69. I’m getting this, any idea’s?

    Fatal error: Uncaught Exception: 102: Session key invalid or no longer valid thrown in /home/readys/public_html/apartmentgroup/floritas/gallerytest/fb-sdk/src/facebook.php on line 515

    1. i have the same problem… do you solve it?

    1. Hi how did you manage to resize all thumbnail????

  70. 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.

  71. @Manuel: Hi there! if you want pro help please go to the ‘Requests’ section of this site and send me your email. let’s see what i can do for you. 🙂

  72. Great knowledge you have shared with us and before read your post i was unaware about it and thought that it is impossible for me to do it, but after read your post i am feeling that it is easy and it will help me a lot.

  73. Thanks, good code.

  74. 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

  75. 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!

  76. Hi Mike…

    I am using all what you have said however it does not display my photos, here is the page and all it displays…

    http://plur.com.tw/new/FB_photos/index.php

    This is the owner ID I think: 206589206046378

    This is my app id & secret, appId: 289388427741701, secret: 4ac6fe1b669eed3f8634c31ff6aa9b13

    please help me!

  77. Is it feasible to use this code against a user’s profile rather than a page — if the app requested the appropriate permissions: user_photos,friends_photos ?

    Mike — Any ideas? on this

    1. Hi @David, I was unsuccessful when I tried that using this script. Maybe other methods will do..

  78. THANK YOU SO MUCH! I’ve been searching and struggling to create a way for my web customers to organize their own photos on their websites, and this is perfect!!

    1. You’re welcome @Doe! 🙂

  79. marcello Avatar
    marcello

    Hello, thanks very much.
    I was wandering if there is a way to limit the query to the latest album, for instance to show only the last 12 albums?
    Thanks again…

    1. add this the the end of the fql ORDER BY created DESC LIMIT 12;

  80. I got it to work 😉

    Love the script .

    1. Nice one! Thanks @mensajes!

  81. Can we use this with groups?

    1. Hi @Derrick! Haven’t tried that. Sorry..

  82. Hello ,
    i use this. It OK with PAGE ID = 266263583420755
    But i can’t use with PAGE ID = 295586073833704

    i should to do ?
    i don’t understand it T^T

  83. 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.

  84. 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

    1. Hi @Rathan, regarding the thumbnail size, that can be fixed using CSS. You may try this method: define the size of your thumbnail in a div then use something like overflow:hidden

  85. Anonymous Avatar
    Anonymous

    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

  86. Anonymous Avatar
    Anonymous

    Hi Everyone,

    I’ve had a read through the above messages and cant see where anybody has mentioned my query.

    I am getting duplicate albums and incorrect album names, ones that don’t even exist!!

    My Page: http://alturl.com/xp7qp
    Facebook Page: https://www.facebook.com/TheCourtenay?sk=photos

    Please help!!! Thank you

    Alex

    1. Hi @Alex, Profile Pictures are different from you Wall Photos. If you want to unselect an album you have to do something like:

      SELECT aid, cover_pid, name FROM album WHERE owner=your_page_id AND aid != id_you_dont_want_to_select

    2. Anonymous Avatar
      Anonymous

      Thanks for your reply, but it doesn’t seem to have worked. I added:

      AND aid !=(and the id of the album)

      …but the album had a string of 3 number separated by .’s:

      https://www.facebook.com/media/set/?set=a.372559612758179.110315.372556249425182&type=3

      I see that the last string is the page ID (372556249425182), but not sure what to use for the album ID?

      Sorry to be a pain 🙁

  87. Anonymous Avatar
    Anonymous

    Thank you for the great script!
    its so rare to find something that works on the first go.
    well done!

  88. I got it to work 😉

    Love the script .

  89. patrick Avatar
    patrick

    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?

    1. 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?

  90. Hi Mike! I love this 😀 Been searching on the net for this for days now. Only question how can I add comments/likes to each photo?

    1. Thanks Patrick! honestly, I haven’t tried creating a hack on that feature. Maybe I’d post about that soon.

  91. 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!

    1. Thanks jdogfantastic, and to your recommendation. 🙂

  92. Anonymous Avatar
    Anonymous

    I love it!
    Great job man!

    1. Thanks, I’m glad it helped. 🙂

  93. 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

    1. Could you show us how to load the gallery via ajax? I took a look at your source but could not figure it out. Thank you very much.

    2. 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);

    3. Part 3 😮

      //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 🙂

  94. 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!

    1. 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. 🙂

  95. Thanks you, this post very help me!!!!

  96. 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!

  97. Anonymous Avatar
    Anonymous

    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?

  98. Great work Mike. Very useful
    Thank you very much!

  99. Any idea how to do this, but display the images in a gallery on an iphone application?

    Thanks

  100. Hey mike,

    Nice code, but i cant figure out how to select only 3 albums out of 30, without having to define 27 of them. That seems a bit ineficient to me xD

    Any clues?

  101. Just wondering if there is a way to tell the code to exclude a certain album? (ex: unrelated ‘Wall Photos’ album)
    Thanks!

    1. i’m trying to do the same thing with no luck. anyone found the correct solution? i believe you have to run multiple queries to filter, but i am not sure.

    2. $fql = “SELECT aid, cover_pid, name FROM album WHERE owner=xxxxYOU ID xxxxx AND name<>’Wall Photos’ AND name<>’Cover Photos’ AND name<>’Profile Pictures’”;

      Replace this in to line 28 of the index.php it get rid of profile pics, wall photos & cover photos

    3. @xcodeee – thank you! That’s exactly what I needed!

  102. 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’”;

    1. Thanks for posting it here. Something like this will be included in the next version. Thanks again!

    2. Very helpful and much needed feature.

  103. Hi mike… nice code but i have a question… because it is not necessary get an user acces toke to do this?

    1. Hi Anthony, there’s no need to get user’s token since it works for fan pages only.

  104. Anonymous Avatar
    Anonymous

    Greet work, It solve my problem, Thank you very much

  105. 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?

  106. 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

  107. Hi Steve189 and Daniel, did you see any error messages? Did you try to update your fb php sdk? The code still works for me, it’s just the demo of this post isn’t updated yet (gonna update if i have time, hehe). And also the latest version still works http://www.codeofaninja.com/2012/05/display-facebook-data-to-your-website.html

  108. Anonymous Avatar
    Anonymous

    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!

    1. Hi Anonymous, what’s the actual problem? Any error messages?

    2. Anonymous Avatar
      Anonymous

      The script isn’t loading any images and breaks the site template, so I know I’m doing something wrong! If you go to http://lilorphanhammies.org/scrapbook you can get an idea of the problem.

      Thanks!

    3. Anonymous Avatar
      Anonymous

      Hmm. I’ve tried creating a new FB app, just in case there was a problem with the first one, but I still can’t get this to work.

      Any ideas?

      Thanks!

    4. Anonymous Avatar
      Anonymous

      Still no errors, but it breaks my PHP template and causes an otherwise validating page not to validate. The inclusion of this script causes div’s that were closed to read as unclosed tags. Any ideas?

      Thanks again!

  109. Mike how do you limit the results of the photo gallery to < 7 per row? I need it to be 4 images per row. Thanks!

  110. 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

  111. N/M Mike I got it! Thanks for an AMAZING script!

  112. 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

  113. 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.

  114. Anonymous Avatar
    Anonymous

    “102/Session key invalid or no longer valid

    How to solve it?

  115. Anonymous Avatar
    Anonymous

    102: Session key invalid or no longer valid

    How to solve it, Mike?

  116. 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 🙂

  117. 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

  118. 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

  119. Can anyone who is more familiar with this please help me out? I don’t know SQL at all and I need to impliment a client’s facebook page photos into their website.

  120. 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.

  121. 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

  122. Hi Mike, thanks for the awesome App.
    However I cant seem to display my own photo’s. Ive read your comments to others. But Im not sure how to find my owner ID or how to set access to users?

    The URL is http://www.graceandfavourthelabel.com.au/fb_test/

    And the
    ‘appId’ => ‘503288736354725’,
    ‘secret’ => ‘7fae72353b28f273f07bc6a27bdcc6f9’

    Could you please help me. Cheers.

  123. 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

    1. Please see my reply to simran..

  124. 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.

    1. I think you’re using it for a Facebook profile, but this only works for Facebook fan pages.. If you don’t have the appId and appSecret, you should do this http://www.codeofaninja.com/2013/02/facebook-appId-and-appSecret.html

  125. 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.

    1. I think this script won’t work in the localhost since it requires cURL. Please use a real web host like http://www.bluehost.com/track/ninjazhai/, I would really appreciate if you’ll buy using my link! Other option is using a free webhost that offers cURL. but it has so many limitations.

  126. You can limit it by specifying the album id (aid) in the query. Take a look at the albums table https://developers.facebook.com/docs/reference/fql/album/

    1. Sylvain Avatar
      Sylvain

      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.

      1. Sylvain Avatar
        Sylvain

        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 ?

        1. try:
          WHERE aid=’151037504938143_1073741825′”;

  127. Hello, why in yahoo small business hosting won’t work? On localhost xampp working everything but when i upload it to yahoo account won’t work :/

    1. Hi Lukas, really this code works on localhost xampp? Regarding the yahoo small business hosting, did you see any errors when you tried to run the code?

  128. how to apply validation on events .. i will try but no results

    1. What kind of validation, @b9ca306813ad506985374ffe5ca90fb7?

  129. everettantony Avatar
    everettantony

    Would you be able to also integrate each photos Like Count in your gallery?

  130. 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.

    1. Hi @DavidAtlanta, you can continue to use the same key and secret code for those.

  131. chris Avatar
    chris

    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?

    1. Hi @chris, yes, I think you can try to use the LIMIT clause? You can see the approach I used here http://www.codeofaninja.com/2012/05/display-facebook-data-to-your-website.html

  132. 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?

  133. marius Avatar
    marius

    How would I modify this script to display only the photos fromm all albums?

  134. thank you very much helped me a lot.

  135. 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.

    1. Please do help as I am using the script on a nursery website for parents to view and they are now unable to view it. I would post my website link but I am not sure if it is allowed.

      Thanks

      1. could it possibly be because of privacy settings changing on facebook page? is your page set to public?

  136. Konstantinos MKink TattooPierc Avatar
    Konstantinos MKink TattooPierc

    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! 🙂

    1. Hi @konstantinosmkinktattoopierc, are you sure you aren’t using a LIMIT clause in your query? Regarding the ‘headers already sent’ message, you can learn more here http://stackoverflow.com/questions/8028957/headers-already-sent-by-php/8028987#8028987

  137. Hi Mike,

    How do I alter this so that a user can upload an album from Facebook and then view it on my website automatically?

    1. Hi @bc8f4db8b85fc5c8a277d995b9f9c435, that’s actually what this script does.

  138. You’re doing great job! Thanks

    1. Thanks for your feedback @disqus_87bUp6vMMa!

  139. 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.

    1. Hi @Handy, you can specify an album_id in the WHERE clause..

  140. Rakesh Shetty Avatar
    Rakesh Shetty

    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 ?

    1. Hi @Rakesh, it will work for any facebook page without restrictions such only!

  141. Hi , Great job 😀
    Can I add a like button to each image when it open to like it by others ?

    1. Hi @daghes, yes you can do that but it will be another job. You can also use other jQuery plugin as your lightbox to achieve it.

  142. Mika Välimäki Avatar
    Mika Välimäki

    I cant get this to work. Not even the examples work on my web page. What is it about?

  143. I don’t see anyone else having this problem, but I’m having a 500 Internal Server Error while trying to run this code… Page is: http://zombieleader.com/gallery/test/ Funny thing is, I have this exact code working beautifully on another page… I’ve tried changing the PHP permissions for the page in question, but still no luck. Any help would be most appreciated!

    1. ninjazhai Avatar
      ninjazhai

      @mikavlimki and @KyleP555 , would you show us your code? So we have some clues debugging it..

  144. 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

    1. ninjazhai Avatar
      ninjazhai

      Hello @mglinn, we’re not using the fb sdk in the tutorial above… Please follow the tutorial to make it work, or you can just download the code if you want…

      1. thank you for your reply. And I would like to suggest , that there is prev -next buttor or load more button for load new feed or new photos . Eg . http://rpnzl.com/code/lazyjson-v1.0/demo

        1. ninjazhai Avatar
          ninjazhai

          @mglinn, we already have that on the “photos” page, you can see this effect if you download and use the source code for albums with many photos… I’m working on the “albums” page “load more” feature… Thanks for your suggestion! 🙂

      2. I would like to suggest to add prev – next button or load more button rather than scroll new feeds. eg . http://rpnzl.com/code/lazyjson-v1.0/demo

      3. Hi, I would like to suggest to make prev – next button or load more button rather than scroll down new feed function . Eg – http://rpnzl.com/code/lazyjson-v1.0/demo

      4. Hi, Thank you and I would like to suggest to add prev – next button or load more button . like this eg – http://rpnzl.com/code/lazyjson-v1.0/demo

  145. 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.

    1. ninjazhai Avatar
      ninjazhai

      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!

  146. Hi, I test it and it’s everything ok.
    But when I test it on actual running website and after two days , it show error
    file_get_contents(http://graph.facebook.com/v1.0/451510405966669/albums?limit=9): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden

    some say that my remote server block this connection.

    1. ninjazhai Avatar
      ninjazhai

      Hello @mglinn, are you on shared hosting server? Sometimes a shared hosting is blocked by Facebook because there were too many requests on that server…

      Also, you have to get your access token..

      1. Hi, I test it in my vps and now I change to digital ocean, but file_get_contents error occur after two days because of too many users 🙂 .
        And I want to know how to add access token ?

        $json_link = “http://graph.facebook.com/{$fb_page_id}/albums?fields=id,name,description,link,cover_photo,count”;
        Do I need to add at the end of the graph url ?
        Thank you for your reply .

        1. ninjazhai Avatar
          ninjazhai

          @mglinn, sorry for the late reply, on other tasks like this, you should add an access token, you can obtain one by creating an app and then using the URL:

          https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&grant_type=client_credentials

          1. Recently bought your script. Can you provide quick tutorial for creating fb app and token for us in Download file on sellfy?
            How can I avoid this error with .htaccess on shared hosting? Just tried this:
            php_value allow_url_fopen On (nothing happens)
            allow_url_fopen=on (gives 500 internal server error)

          2. Hi @Help, you can check this tutorial out to get those IDs http://www.codeofaninja.com/2013/02/facebook-appId-and-appSecret.html

          3. Put it in index.php on line 72.

            $access_token=”AppID|AppSecret”.

            The same error, nothing happens.

  147. ninjazhai Avatar
    ninjazhai

    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!

  148. 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!

  149. …don’t worry, I’ve actually clicked on the pro demo and the answer was there! Thanks 🙂

  150. Marco Civita Avatar
    Marco Civita

    hi, i have problems by using your script:

    http://www.codeofaninja.com/2011/06/display-facebook-photos-to-your-website.html

    It says:

    Warning: json_decode() expects at most 2 parameters, 4 given in D:Inetpubwebs{xxxx}testindex.php on line 35

    How to solve?

  151. Just ran across this today, and still works with no problems. Thanks so much!

  152. gianluca Avatar
    gianluca

    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

  153. Shamma Lammadingdong Avatar
    Shamma Lammadingdong

    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!

  154. Shamma Lammadingdong Avatar
    Shamma Lammadingdong

    Please disregard my previous post. Figured it out. 🙂

  155. Erin Lima Avatar
    Erin Lima

    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!

    1. 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);

  156. Rajdeep Avatar
    Rajdeep

    Warning: file_get_contents(http://graph.facebook.com/v2.3/887680754587029/albums?fields=id,name,description,link,cover_photo,count&access_token=“Here is my access token”): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in C:wampwwwgalleryindex.php on line 36Call Stack#TimeMemoryFunctionLocation10.0007255096{main}( )..index.php:020.0007256656file_get_contents ( )

    1. @Radjeep, you need to include your access token, if you downloaded the code you won’t have any problem. Here’s a simple tutorial to get your FB IDs http://www.codeofaninja.com/2013/02/facebook-appId-and-appSecret.html

  157. This is really awesome script and Mike is developer who wants to help you to fix errors after you integrated his script in your own site.

    1. Thanks for the kind words @Haris! I’m glad you were able to use it in your site. 🙂

  158. Temsu Lemdor Avatar
    Temsu Lemdor

    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.

    1. Hello @temsulemdor, wow, thanks for the kind words and recommendation! We will continue to update the tutorial and source code to comply with all the FB api updates.

  159. Greg Thompson Avatar
    Greg Thompson

    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”
    },

    1. 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’] : “”;

  160. Zaibatsu Avatar
    Zaibatsu

    Hello Is it safe to display the access token in public?? Because the image is displayed only when the access token is provided.

    1. Hello @Zaibatsu, That’s a good question, thanks!

      Here is my answer: it is not okay to display your access token in public. The image src URL will be changed by Facebook during display so it will not show your access token.

      See the cover photo image src URL in the demo…

      1. Thanks for the info Mike.

        1. You’re welcome @Zaibatsu!

  161. codeview Avatar
    codeview

    I just paid for & downloaded the PRO version. Out of the box I’m seeing this error: Notice: Undefined index: next in C:PATHTOindex.php on line 82

    1. Hello codeview, thanks for purchasing the code! About your issue, would you try to replace this:


      $next_page = $obj['paging']['next'];

      to this:


      $next_page = isset($obj['paging']['next']) ? $obj['paging']['next'] : "";

      1. codeview Avatar
        codeview

        Thanks Mike, that worked!

        1. Glad it worked, you’re welcome @codeviewer!

      2. codeview Avatar
        codeview

        That worked, thanks!

      3. codeview Avatar
        codeview

        I also had to do the same change on line 15 in albums_more.php

        1. Oh yes, thanks for reminding us!

  162. 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.

    1. Hello @Cris, glad you found it working great! About your question, how about using cURL? See an example here http://stackoverflow.com/a/3979882

  163. I can’t get this facebook page album.
    Here is the page link : https://www.facebook.com/maungphoenyan?fref=ts
    It show the error :
    file_get_contents(https://graph.facebook.com/v1.0/270477069661401/albums?limit=9

    1. Hello @mglinn, you have to make your Facebook page public. It must be view-able even if the user is not logged in on Facebook.

      1. Thank you Mike.

  164. Mauri Cabrera Estrada Avatar
    Mauri Cabrera Estrada

    I have fixed it to use it with Graph API 2.5, if anyone needs help, please contact me, thanks a lot for the work!!!

    1. Hi @mauri, thanks for informing us that fb graph api v2.5 can now be used!

    2. quickjeff Avatar
      quickjeff

      @mauricabreraestrada I have 2.5 and cannot pull the cover photos, any help? I saw that the cover_photo is replaced with album_id but not sure if there is another solution? I tried both and still get an array notice.

  165. Otara Gunewardene Avatar
    Otara Gunewardene

    @ninjazhai
    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.

    1. Hello @otaragunewardene, thanks for reporting this, we appreciate it! I just updated the post, thanks again!

  166. quickjeff Avatar
    quickjeff

    @ninjazhai 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!

  167. Hello @quickjeff, would you link us to your test URL and FB page ID? Our script only need an access token. What do you mean by OG 2.5, is it the same as FB Graph API v2.5?

    1. quickjeff Avatar
      quickjeff

      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.

  168. @quickjeff, you can also try using another access token. Old access tokens sometimes does not work properly.

    1. quickjeff Avatar
      quickjeff

      Hi Mike, already tried this. I created a new app, requested a new token. Still encountering the issue.

  169. Hello @quickjeff, would you send us your test url and fb page url?

  170. I’m going to test this source code with Graph API 2.5, maybe we’ll just have to play around with the returned JSON values.

    1. quickjeff Avatar
      quickjeff

      Hi mike, I have it setup in a dev environment, can I send you access by email ? It’s a client site.

  171. 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?

    1. Hello @Jay, which Facebook page are you trying to use with the script above? Any error message you see? Would you send us your test URL?

      1. It is done; I was putting pageid wrong.

  172. Hi @quickjeff, sure, send me an email [email protected]

    1. Glad you found it impressive @denisdee ! Thanks!

  173. 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

    1. @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!

  174. Anoop M A Avatar
    Anoop M A

    I have a public album ,so there is no access token or app key ,how do I process the URL

    1. Hi @anoopma , access token is needed by our code.

  175. Hi @anoopma, this should be working by now.

  176. Pavel Lehoucq Šípek Avatar
    Pavel Lehoucq Šípek

    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.

    1. Hi @pavellehoucqpek, I don’t think so. But you can always try. If it returns an error, it means it is not allowed.

  177. Mark Bagnall Avatar
    Mark Bagnall

    Is it possible to show the photos without having to specify an album?

    1. Hi @mark_bagnall, we haven’t tried that yet. Facebook has API for albums and photos only. What exactly are you trying to accomplish?

  178. Hi @denisdee, the code is already provided on the tutorial above. I think you just need to generate the correct page access token to make it work.

    1. Hey Bob, how may I help you?

Leave a Reply

Your email address will not be published. Required fields are marked *