Use Facebook CDN to host website photo gallerys

I was thinking about how to retrieve photos from Facebook photo gallery’s and came across a number of solutions. Most of the solutions were for blog or CMS and furthermore required caching your credentials in a database along with a few other hoops in order to access your albums and display them on a third party site. I thought this was a bit odd as if you want to share photos on your blog or site you should be able to just make the album public and use Facebooks API to connect since they are going to be public at that point. After poking around this ended up being much easier than expected and it works with Facebook Fan Pages which is where I think this would be most useful.

  1. You need to create a Facebook application account which will provide you with your appId and secret.
  2. Next you need to get the PHP SDK from GitHub. All you need is the facebook.php page but feel free to grab the ZIP and explore. There is an example to experiment with.
  3. Lastly you can use the code provided on Google Code as a basic start to implementing a photo gallery on your site.

The code displays thumbnails, source images along with name’s (caption’s) below each image that have them and finally the source which you can use to derive other goodies that you might want to use in you gallery. Some examples are different size thumbnails, id, comments, etc.

*Note that the script does not parse double quotes in photo captions well at this point.

If you notice any issues, room for improvement or features feel free to leave a comment or post an issue over at the Google Code page.

This entry was posted in coding and tagged , , , . Bookmark the permalink.

11 Responses to Use Facebook CDN to host website photo gallerys

  1. chung says:

    doesn’t it violate any law/s? i would like to try this but I’m not sure if it’s really legal

  2. Please refer to This script parses a public albums. There are a number of scripts that can display private photos by storing credentials which may violate TOS but this does not store end user data except what a traditional web-server would. If you find otherwise please let me know.

  3. chung says:

    would it be OK if I’ll give your link to Facebook team? I’m not really good in English and can’t understand most of their policies… I would like them to be the one to evaluate if this steps are legal or not…

  4. chung says:

    i wasn’t able to thoroughly understand your post until now… i’m sorry for being a disturbance… next time i’ll understand it first before leaving a comment… as i thought, this isn’t done without permission from them, right?

  5. The Facebook API is designed to facilitate data sharing. The code demonstrated in this blog post is for accessing public photos and information on Facebook, it is not intended to access private information though there are a number of third party applications that do this: or or

  6. Troels says:

    Hey there

    Wow a great post, very useful.


  7. Jon Dering says:

    So, is it legal to use user’s public photos directly from facebook’s cdn? I am just wondering in terms of a) is it TOS compliant to publicly show user’s photos on 3rd party site even if you have their permission and b) won’t facebook frown upon you using up their bandwidth?

  8. @Jon, I cannot provide legal advice but feel free to view Facebook’s TOS: and


    “For content that is covered by intellectual property rights, like photos and videos (IP content), you specifically give us the following permission, subject to your privacy and application settings: you grant us a non-exclusive, transferable, sub-licensable, royalty-free, worldwide license to use any IP content that you post on or in connection with Facebook (IP License). This IP License ends when you delete your IP content or your account unless your content has been shared with others, and they have not deleted it.”


    “When you publish content or information using the Public setting, it means that you are allowing everyone, including people off of Facebook, to access and use that information, and to associate it with you (i.e., your name and profile picture).”

    This script leverages the Graph API.

  9. Jon Dering says:

    Thanks for reply @Stephen. Great article.

  10. Biswajit Das says:

    its possible with WordPress ?
    and how to ?

  11. If you mean possible to integrate the gallery, I imagine it would be but have not tried to do so myself therefore would not have a how-to for you.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>