Coder Social home page Coder Social logo

dejanstojanovic / facebook-album-browser Goto Github PK

View Code? Open in Web Editor NEW
74.0 20.0 43.0 144 KB

jQuery plugin for browsing public albums of a Facebook account

Home Page: http://dejanstojanovic.github.io/Facebook-Album-Browser/

License: MIT License

CSS 11.81% JavaScript 88.19%
photos jquery-plugin album javascript facebook facebook-api

facebook-album-browser's Introduction

Facebook-Album-Browser

Reponsive jQuery plugin for browsing public albums of a Facebook account. Plugin is suitable for both desktop and mobile websites.

ScreenShot

What can I do with it

The main purpose of this plugin is to enable to embed and customize phot albums in your website without being limited with Facebook styling. It also allows you to use it as picker as it raises events for clicked album/photo.

How to add to a page

Add a reference to jQuery library, this plugin library and this plugin CSS stylesheet

<link rel="stylesheet" type="text/css" href="../src/jquery.fb.albumbrowser.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="../src/jquery.fb.albumbrowser.js"></script>

Simply add a container (div or any other element) and apply the plugin to it.

<div class="fb-album-container"></div>

<script type="text/javascript">
    $(document).ready(function () {
        $(".fb-album-container").FacebookAlbumBrowser({
            account: "natgeo"
        });
    });
</script>

What are options for plugin

The following are options for the plugin which are used to congigure the plugin instance:

Name Default value Description
account Facebook account for which albums and photos will be fetched and displayed. This parameter is mandatory and must be provided in order for plugin to work
accessToken Access token for accessing non public content for the Facebook account
showAccountInfo true Show Facebook account name and icon above the browser
showImageCount true Show number of protos in each album. Default value is
showImageText true Show or hide text associated to photo in image preview (lightbox)
skipEmptyAlbums true Skip albums for which plugin was unable to fetch at least one photo
skipAlbums [] List of IDs or names or combined IDs and names of albums which will not be browsed (e.g ["Profile Pictures", "Timeline Photos"])
thumbnailSize 130 Size of the thumnails for the album and photos (in pixels)
lightbox true Show full size image in a lightbox style when clicked
photosCheckbox true Allows using of plugin as an image multipicker
likeButton true Adds Facebook like button for image on image lightbox preview
shareButton true Adds Facebook share button is like button is enabled. Adds AddThis buttons if addThis is set with AddThis pub-id
albumsPageSize 0 Page size of album browsing. If set to 0, paging is off
albumsMoreButtonText "more albums..." Text value for more button when album paging is on
photosPageSize 0 Page size of album photo browsing. If set to 0, paging is off
photosMoreButtonText "more photos..." Text value for more button when photos paging is on
onlyAlbum null Skips album browsing and starts browsing album with specific id
showComments false Shows comments of the photo when previewing photo
commentsLimit 5 Number of comments per page
addThis null Enables sharing via AddThis buttons if AddThis pub-id is provided and shareButton is enabled

Events

The following are events raised by plugin:

Name Description
albumSelected Handler function for event raised when album is selecetd in the browser
photoSelected Handler function for event raised when photo is selecetd in the browser
photoChecked Handler function for event raised when photo is checked
photoUnchecked Handler function for event raised when photo is unchecked

Every event functin returns an object which holds three properties:

  • id - image id in Facebook database
  • url - large image url
  • thumb - thumbnail image url

Demo

Test document test.html is contained in the soolution. You can download it for testing or use the following code:

<div class="fb-album-container"></div>

<script type="text/javascript">
 $(document).ready(function() {
      $(".fb-album-container").FacebookAlbumBrowser({
        account: "natgeo",
        skipAlbums: ["Profile Pictures", "Timeline Photos"],
        showAccountInfo: true,
        showImageCount: true,
        lightbox: true,
        photosCheckbox: true,
        photoChecked: function(photo) {
          //Handles photo checkbox checked
        },
        photoUnchecked: function(photo) {
          //Handles photo checkbox unchecked
        },
        albumSelected: function(photo) {
          //Handles album thumbnail clicked event
        },
        photoSelected: function(photo) {
          //Handles photo thumbnail click event
        }
      });
    });
</script>

To see the plugin live in action checkout demo on CodePen

ScreenShot

AddThis support

Starting from version 1.3.1 plugin supports sharing via AddThis sharing. It allows you to share facebook URL to an image direcly from the image lightbox preview in a plugin. All that needs to be done is to enable sharing button and provide AddThis pub-id to plugin in initialization settings and you are set to share Facebook photo URL direcly on your website.

<div class="fb-album-container"></div>

<script type="text/javascript">
 $(document).ready(function() {
      $(".fb-album-container").FacebookAlbumBrowser({
        account: "natgeo",
        showAccountInfo: true,
        lightbox: true,
	    shareButton: true,
        addThis:"ra-xxxxxxxxxxxxxxxx"
      });
    });
</script>

Using it as a photo-picker

This plugin has buit in support for multiple picker, wich allows you to browse through albums and photos and pick them. The plugin will store all picked photos in an object array and make them available.

You can either access picked images on your custom page event or you can hook to plugin's photoChecked and photoUnchecked event.

  <div class="fb-album-container">
  </div>
  <script type="text/javascript">
        $(document).ready(function () {
          $(".fb-album-container").FacebookAlbumBrowser({
                account: "natgeo",
                accessToken: "775908159169504|cYEIsh0rs25OQQC8Ex2hXyCOut4",
                skipAlbums: ["Profile Pictures", "Timeline Photos"],
                showAccountInfo: true,
                showImageCount: true,
                showImageText: true,
                lightbox: true,
                photosCheckbox: true,
                photoChecked: function(photo){
                    console.log("PHOTO CHECKED: " + photo.id + " - " + photo.url + " - " + photo.thumb);
                    console.log("CHECKED PHOTOS COUNT: " + this.checkedPhotos.length);
                },
                photoUnchecked: function (photo) {
                    console.log("PHOTO UNCHECKED: " + photo.id + " - " + photo.url + " - " + photo.thumb);
                    console.log("CHECKED PHOTOS COUNT: " + this.checkedPhotos.length);
                },
                albumSelected: function (photo) {
                    console.log("ALBUM CLICK: " + photo.id + " - " + photo.url + " - " + photo.thumb);
                },
                photoSelected: function (photo) {
                    console.log("PHOTO CLICK: " + photo.id + " - " + photo.url + " - " + photo.thumb);
                }
            });
        });
  </script>

ScreenShot

Acquiring the right access token

Follow the steps to get the access token to use the plugin

  1. Login to developers.facebook.com with your Facebook developer account
  2. Create an App with WWW platform selected
  3. Add url of the website where you are about to use this plugin and save the changes
  4. In a new browser tab visit https://graph.facebook.com/oauth/access_token?client_id={app-id}&client_secret={app-secret}&grant_type=client_credentials (values for app-id and app-secret parameters take from the app settings page)
  5. After loading the url above you will get the access token in a response. Sopy the access_token value to plugin settings javascript code you use to initialize the plugin.
  6. Enjoy using the plugin :)

Note: In order to make this plugin work with Facebook account photos you need to allow user_photos permission in your Facebook App that is used to authenticate and add permissions. Please read the article on Facebook https://developers.facebook.com/docs/apps/review.

For testing purposes you can use Facebook App test users. More about using test users you can find at https://developers.facebook.com/docs/apps/test-users/.

A word of author

So far I developed and mainatined this plugin by myself, so sometime I might not have time to respond to your requests and reported bugs. Feel free to participate. Every line of code, every comment or idea would mean a lot to maintain this free plugin project alive and up to date.

It would mean a lot to me to know where it is used, to see how it works and maybe give me an idea what can be improved in order to better fit in to various websites.

I created an issue where you can add all your website URL/URLs where you are using this webiste.

Thank you all in advance.

facebook-album-browser's People

Contributors

bitdeli-chef avatar bryant1410 avatar dejanstojanovic avatar sanjinc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

facebook-album-browser's Issues

Issue

I can't seem to get this working, even though my Page is public and I am using access tokens correctly.
The page remains blank, so I'm guessing that maybe the API call is failing ?
Any help would be much appreciated,
Thanks.

Mobile Access

I recently added this plugin to my website i2robotics.org and I look at it on my phone and discovered 2 issues. The first one being that when opening a gallery the first time a gallery is selected it slides up weirdly and then requires you to click again to open it, the second issue is that the images become weirdly sized when being accessed from a mobile device. Please advise me on how to continue. Thank you.

click on photo

Hi, if you try to click on a photo if works... so light box opens. Then if you reclick on the same one it doesn't

function request

can you add an option for displaying the comments @ a picture?
it would be nice if the popup can display the image and comments in 1 popup

share photos from lightbox

Hello Dejan!
I still tying to share the images from lightbox....
I try to do it using addthis, but i can´t.
They tell me that I´ve to call the addthis.init(); and addthis.layers.refresh(); functions in the same function that loads the lightbox... No idea of how to do it, and not much help in google

Those are the codes they give me to put into the body of the html.

<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-50360b776f77c6a6" async="async"></script>
<div id ="botones" class="addthis_sharing_toolbox"></div>

Thank you

image resolution

How to change link to photo? Cause it's not in full resolution. I opened photo via facebook account and link was [https://scontent.xx.fbcdn.net/hphotos-xfp1/t31.0-8/11894415_142201052791249_2462838957330698595_o.jpg] but plugin opens photo like that [https://fbcdn-photos-d-a.akamaihd.net/hphotos-ak-xfp1/t31.0-0/p480x480/11894415_142201052791249_2462838957330698595_o.jpg]. It is not the same resolution. Plugin thumb image link is [https://fbcdn-photos-d-a.akamaihd.net/hphotos-ak-xfl1/v/t1.0-0/p130x130/11959959_142201052791249_2462838957330698595_n.jpg?oh=4b3d65c20143300a78679da6e3ad9903&oe=56694DA0&gda=1450735549_4862cc3341cbcfd97d6cbee0f8c7f86c]. It is so tiny (130x130)... How can I change all plugin links (image-thumb, full image, album cover image and etc) to one link which will always direct to full resolution image? Like that [https://scontent.xx.fbcdn.net/hphotos-xfp1/t31.0-8/11894415_142201052791249_2462838957330698595_o.jpg]

like/share button not showing

hi any idea why the like and share buttons aren't showing?
i have them set as
likeButton: true,
shareButton: true,

i thought it was just on my page but your codepen doesn't seem to show it either. any way to fix this?

Facebook permissions

Hello,
I can't access my facebook albums. I changed natgeo to my fb name. The only thing that is displayed is my profil picture and my user name.
I read about the instruction to allow user_photos. However, I am not into app programming and have no idea what to do. I want to use your plug in from a html website, not from an app, so how am I supposed to grant rights to an app?

App approval

Hello,
It might be my own misunderstanding or something else but let's say I am an admin of a tattoo page and I would want to get images from that page to a website, in that case do I need to get my app approved for it to work correctly or no?
Currently I have followed the instructions and got far enough to get the name and profile picture of that page to show but it wont load the images, the loader icon just keeps going and going. I don't see any errors as well.
Seeing as it does show the name and profile picture of the page, I am quessing that everything should be fine with my configuration and thus must be something else that keeps the images from loading, as in the app needs to be approved, right?
Or perhaps there is something wrong with my app permissions? I am not sure. :(

Apologies for the long post and my own misunderstanding. I can also post a link to the site if you think it is needed.
Thanks in advance.

Selecting Albums for Viewing

Hello again,

I am trying to select a couple of albums only to show in a gallery is there an easy way to do this?

Thank you

photosCheckbox

Hello
I don't understand what the photosCheckbox do if it enabled
Thanks :)

Thumbnail image size

How do I change the size of the thumbnail image being requested from Facebook?

Facebook API level

Hi,
Which FB API level you related on while building the plugin?
I think there is a problem with the new API (2.4), which doe's not return the data objects you rely on...
I'll explain:
I have a problem with fetching the albums/photos with your plugin, so I did some testing using the Graph API Explorer.
When using the 2.4V API, a GET request to "albums" return an object with the following structure:

{
  "data": [
    {
      "name": "Timeline Photos",
      "created_time": "2011-06-13T23:31:19+0000",
      "id": "id_number"
    },
    {
      "name": "Profile Pictures",
      "created_time": "2010-10-07T15:56:34+0000",
      "id": "id_number"
    },
    ......
}

Which doesn't fit your code... and fails to retrieve the albums/photos...

When using the 2.2V API, (which you are using) a GET request to "albums" return an object with the following structure:

{
"data": [
    {
      "id": "10150205173893951",
      "from": {
        "name": "National Geographic",
        "category": "Media/News/Publishing",
        "id": "23497828950"
      },
      "name": "Timeline Photos",
      "link": "https://www.facebook.com/album.php?fbid=10150205173893951&id=23497828950&aid=320000",
      "cover_photo": "10151137816808951",
      "count": 508,
      "type": "wall",
      "created_time": "2011-06-13T23:31:19+0000",
      "updated_time": "2015-08-07T04:20:20+0000",
      "can_upload": false
    },
    ...
]
}

Is there something I am missing? or am I right?

[Solved]How to use

Hello
I search a possibility to add on my website some albums , i have found your script but i don't uderstand how to use and configure, i have change the name of "account" but i don't see nothing
Thanks for you help :)
Edit : i think i have found, have to create an unique username of the fb page :)
Good job this is the first perfect script i found \o/, thanks

How to close the selected picture?

Hello,

I'm using the following code to select a pciture from an album:

$(document).ready(function () {
                            $(".fb-album-container").FacebookAlbumBrowser({
                                account: "me",
                                accessToken:$localStorage.accessTokenFacebook,
                                showImageText: false,
                                likeButton:false,
                                shareButton: false,
                                //photosCheckbox:false,
                                showAccountInfo: false,
                                lightbox:true,
                                showComments: false,
                                photosPageSize: 0,
                                thumbnailSize: 100,
                                photoSelected: function(photo) {
                alert('here'+JSON.stringify(photo)+'--'+$scope.profilePhotos.length)
                                    var imgurl = photo.url;
                                    $scope.profilePhotos[imgindx].photo = imgurl;
                                    $localStorage.profilePhotos = $scope.profilePhotos;

                                    toDataUrl(imgurl,1000,1000, function(base64Img){
                                        alert('imagetoparse')

                                        var name = "photo.jpg";
                                        var parseFile = new Parse.File(name, {base64:base64Img});
                                        var Photo = new Parse.Object("Photos");
                                        Photo.set("user", $localStorage.username);
                                        Photo.set("type", $localStorage.profilePhotos[imgindx].type);
                                        Photo.set("photos", parseFile);
                                        $localStorage.imgcount = ($localStorage.imgcount + 1)
                                        alert($localStorage.profilePhotos[imgindx].type+'--'+$localStorage.imgcount)
                                        Photo.save(
                                            {
                                            success: function(objUser) {              
                                                alert("OK");

                                              },
                                              error: function(error) {
                                                alert("error"+error);
                                              }

                                            }
                                        ).then(function() {
                                            alert('statego')
                                            $state.go("profile_edit")
                                            return
                                        })
                                    })  
                                }
                            })
                        })

the problem is that the selected picture keeps staying on my screen instead of closing down (both the album browser and the picture and return on my screen. Any idea? Thanks in advance.

Read videos

Hello
If i put photos and videos on an album of my page, does your script read the videos ?
Thanks

Is this plugin working still?

Looks like FB changed their privacy settings or something, this plugin doesnt seem to work anymore. I have checked all the demos online and offline as well. Albums are not visible, only accountinfo shows up. Is there a way around it?

Thumbnail Size

I increased the size of the fb-photo-thumb class in css to be 234x234 px. Now the thumbnail src image is still being scaled down to a smaller size, usually 130x130 px.

share photo

Hello!
maybe the possibility to add a "share menu" on each image opened (facebook, whatsapp, twitter, mail,..)? using the photochecked function perhaps?
help please!

single album not working

Even the demo file isn't working. It just display the loading animation forever. When clicking on the icon the link is "undefined"

GROUP page

Can i use the script to get the images from a group page? (public photo's and albums?).

thumb descentre

Hi Dejan
the albumThumb are centered, but not photoThumb
Taking a look js code I see:

var marginWidth = 0;

                            if (prefWidth > 0) {
                                marginWidth = (prefWidth - albumImg.width) / 2;
                            }

var photoThumb = $("", { style: "margin-left:" + marginWidth + "px;display:none;", "data-id": $(result.data).get(a).id, class: "fb-photo-thumb", "data-src": albumImg.source, src: "" });

it doesn´t work: photoThumb appears alway from left to right.

Some help to center the thumb?
Thanks

Dates @usercomments are NULL on IPAD

There is a bug with the display of comments by the pictures.

On computer the dates are OK , on IPAD the dates @comments are 1 january 1970 or all null null null null null null null nul:null

Add option to images folder path

I think you should add an option to set an images folder path.
In my case, I have an images folder for all the images in my projects, so I added to the defaults object a new property:

var defaults = {
            account: "",
            ...
            checkedPhotos: [],
            imagesPath: "src/"
        }

And then on lines : 178, 508, 509
I changed the src attr to:

src: settings.imagesPath + "whatever-image-needed.png"

BTW - your plugin is awesome!

Slow load time due to many images.

Hi,
I have run into an issue, where I'm trying to load 3 different albums in 3 different areas for a single page website. The only thing is that it makes the initial load time very slow.

The amount of images is up to a 100 or so.

I was wondering if there would be a way to perhaps lazy-load the images, thus slowing down the initial page load time?
I'm sure you might be thinking well why do you need a 100 images but the reason is that I'm making a site for tattoo artists and they have quite a lot of images to show.

If anyone has a solution or any ideas. Even if someone could point me in the right direction, then perhaps I could find a solution myself. But having searched for quite a while I haven't come up with anything.

Cheers and best regards.

Issue regarding a specific fan page :(

Hi, guys! First of all, great plugin. Nice job... I have encountered a minor setback and am going out of my mind trying to figure it out.

The thing is i installed the plugin on this beta page I'm making http://fiestadelaflor.com.ar/flor/

Now if i put any other fan page in the "account" field, the plugin works out fine. But if I put the one I need to put, (that is this one https://www.facebook.com/Fiesta.delaflor/) I get an undefined error.

I followed the access token instructions and don't really know why this isn't working. Any thoughts?

Thanx in advanced!

About the accessToken

Which access token should I use for getting a specific user albums?
I am trying to get the albums of a specific user (the user who connect to my app), but for some reason I cant.
I tried using the user access token returned from the getLoginStatus function:

FB.getLoginStatus(function (response) {
    accessToken = response.authResponse.accessToken);
});

and my app's access token which I retrieved like you said from:
https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=APP_ID&client_secret=APP_SECRET

both doesn't work...
Am I missing something??
Thanx :)

Position of the arrow left right of lightbox

Hello :)
i have seen you have update the position of the arrows left and right, i think (it's my opinion) to have the arrows on the left/right position:0 it's not really easy to use, maybe with a little screen but not on 1920 with full screen of chrome, and you can't change image if you click on the image (working with old release)

Lot of albums - pagination

Hello :)
i don't have test but if you have lot of albums is it possible to add a pagination (or something similare) to only show a number of albums each time (with a parameter)

How to show album description?

Thank you for your code, it's very useful but I have some question about it.

How to show album description? I create new facebook album and your code is work but it's not show album description, it show only album title and pictures. Please help me about this issue.

Thank you.

Websites where used

Please, feel free to add URL where you are using this plugin.
It would mean a lot to me to know where it is used, to see how it works and maybe give me an idea what can be improved in order to better fit in to various websites.

Thank you all in advance

share buttons row

Hi! When watching photo into lightbox it seems something wrong with share buttons because it's duplicates constantly, when I click NEXT or PREV arrows, it's always increases (+1) rows of share buttons. What should it be?

About the 'user_photos permission'

First of all, great job and thanks for sharing it.

About the 'user_photos permission', it is required only when creating a new app to get a proper access token, right? It seems to be a thing with the API version 2.4. Why? When using an access token of an old app (API version 2.0) that doesn't have the 'user_photos permission', the plugin works beautifully.

I would like to create a new app for the plugin, a proper one, but Facebook requirements for this item approval it's a herculean task =P

Thanks in advance for any comment or tip. Btw, sorry about my english ;)

Multiple albums of the same page

My issue is that I have a single page website but what I wanted to do is display 3 different albums in 3 different sections from the same page on the website.
When I try that, instead of getting 3 different albums in 3 different sections, they all merge only in 1 section.
You can check this at http://sander2.alimit.com/assets/index.html
I apologize the site is in Estonian. You have to scroll down to "Meeskond" and in the right side click on "Näita tehtud tööd". So there are 3 buttons like that but only the middle one works and it takes all the albums as one.
I'd like to mention that my coding isn't the best and I'm still a newbie when it comes to all this so I'm sure it's something obvious I did wrong. Certainly willing to learn more and understand how everything works.

How make order desc

I want to make order picture newest first. Last post showing first. How can I do that?

Facebook ID undefined.

Thank you for the great script. I have been searching high and low for something like this and this fits perfectly.

The script worked perfectly at first. It managed to display the albums on my facebook page. (http://babooth.com.sg/halloffame.html and www.fb.com/sg.babooth)
However, after i tried access it about an hour later it seemed not able to load. (see attached)

If i clicked on the logo in the page, i get and error from facebook and it pushes me to this page (https://www.facebook.com/undefined?_rdr=p)

I followed the instructions as per the page to get the album Id and access token. Is there something i'm doing wrong?

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.