Skip to content
PHP : Create your own Facebook album gallery
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE
README.md
yofba.php

README.md

YOFBA (Your Own Facebook Album)


Demo


Features

  • Customization :
    • Allow to create a custom JSON feed based on Facebook albums.
    • Then, you can use this JSON feed to create a photo gallery. You can use all html/javascript photo galleries.
  • Optimisation : Create a cache (containing the JSON) to increase the response time.
  • Simplicity : For its implementation/configuration (This is why this project is in one file ).

How it works ?

yofba.php

  1. Get and configure this file
  2. Put on your server
  3. Run code
  4. JSONs have been created

YourPhotoGallery.php

  1. Read JSON feed on yofba.php?getAlbum=%youralbumId%

Examples

Warning

jQuery
var urlToCall = "yofba.php?getAlbum=" + "%youralbumId%";
$.getJSON(urlToCall, function (data) {
  $("#album-name").text(data["album"]["name"]);
  var albumLink = data["album"]["link"];

  [...]

  //Iterate on each photo of the album
  $.each(data["photos"]["data"], function () {
    var imageFullSize = this["images"][0];
  });
}

Warning

If your photo gallery and yofba.php are not on the same domain :
Make sure (in yofba.php) that the CORS calls are allowed for your domain.





Configuration

1. Make Facebook App

Step 1 : Add a New App

Create a new app on : https://developers.facebook.com/apps

Step 2 : Get your App ID and App secret

alt text

2. Configure yofba.php (class : Config)

If a property is commenting "Customize" it is that it must be replaced by your values. These properties are shown in bold below.

  • fb_app_id : Get your App ID in Step 2

  • fb_app_secret : Get your App Secret in Step 2

  • app_fb_json_albums_file_path : Location where the JSONs are stored

  • app_fb_albums_array : List of all albums facebook has recovered, ordered by page.

idPage, namePage
Fill in the id and the name of the page. Use in UI drop-list.
albums : list of all albums
idAlbum, nameAlbum, maxPhotos
Fill in the id, the name (use in UI drop-list) of the album and number of photos to load (Without this parameter, the entire album is loaded). To get the ID of an album, retrieve the "album_id" parameter from the [URL][url_demo_FacebookAlbum].
  • app_debug_mode : If you want debug this app. Use Tools::showMessage(" ",MessageType::Debug) method.

  • app_token : To secure access.

  • app_client_access_number_of_attempts_before_the_tempory_ban_of_the_ip : Maximum number of access attempts in app_client_access_time_between_new_try time

  • app_client_access_number_of_attempts_before_definitely_ban : Maximum number of access attempts failed

  • app_client_access_time_between_new_try : Time between access attempts.

  • app_client_access_file_path : Location where the client acces are stored.

  • app_list_of_fields_album : List of all the Facebook fields you want to retrieve for an album (doc : https://developers.facebook.com/docs/graph-api/reference/album).

  • app_list_of_fields_photos_album : List of all Facebook fields you want to retrieve on album photos (doc : https://developers.facebook.com/docs/graph-api/reference/photo)

  • app_count_facebook_likes : Count the numbers of likes.

  • app_count_facebook_likes_field_name : Name of JSON field for likes counter.

  • app_get_main_color_of_image : Analyse and get main color of an image.

  • app_get_main_color_of_image_field_name : Name of JSON field for main color.

  • app_exception_file_path : Location where esceptions are stored.

  • app_allow_cors_request_from_url : If you want to call the JSONs from another domain, you must fill in all the calling domains.
    Example :

    • yofba.php in subdomain app.yourSite.com
    • yourPhotoGallery_1.php in subdomain photos.yourSite.com
    • yourPhotoGallery_2.php in domain yourSite.com
      The app_allow_cors_request_from_url property in yofba.php should look like this :
const app_allow_cors_request_from_url = array("https://photos.yourSite.com","https://www.photos.yourSite.com", "https://yourSite.com","https://www.yourSite.com");

Optional

CRON

Automate the update of JSONs

Update all albums : cron.sh

#!/bin/sh
/usr/local/php7.1/bin/php /xxx/xxx/demo/yofba/index.php token=yourToken

Or

#!/bin/sh
cd /xxx/xxx/subdomain/ && /usr/local/php7.0/bin/php -f yofba.php token=yourToken
You can’t perform that action at this time.