Skip to content

Commit

Permalink
adding access token
Browse files Browse the repository at this point in the history
  • Loading branch information
carlsverre committed Jul 15, 2015
1 parent 1a2df8c commit 8b00e9b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
9 changes: 8 additions & 1 deletion examples/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
(function() {
$('#photos').FBPagePhotos({ album_id: 235025249884452 });
var ACCESS_TOKEN = "YOUR ACCESS TOKEN";

$('#photos').FBPagePhotos({
album_id: 235025249884452
, access_token: ACCESS_TOKEN
});

$('#photos-2').FBPagePhotos({
page_id: "christy-sverre-art"
, access_token: ACCESS_TOKEN
, albums_cb: function(albums, next) {
var select = $('<select>');

Expand All @@ -23,6 +29,7 @@

$.FBPagePhotos({
page_id: "christy-sverre-art"
, access_token: ACCESS_TOKEN
, albums_cb: function(albums, next) {
next(albums[0]); // you could let the user select here, for simplicity I am just choosing the first album
}
Expand Down
31 changes: 27 additions & 4 deletions src/jquery.fbpagephotos.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Facebook Page Photos (for jQuery)
* version: 1.0
* version: 1.1
* @requires jQuery v1.7 or later
* @homepage https://github.com/carlsverre/jquery-facebook-page-photos
*
Expand All @@ -16,7 +16,8 @@
// this is the bare minimum for default functionality
// will render a gallery of photos into #some_id
$('#some_id').FBPagePhotos({
album_id: '33333'
album_id: '33333',
access_token: 'VALID_FACEBOOK_ACCESS_TOKEN'
});
// allows you to pick the album
Expand Down Expand Up @@ -106,6 +107,10 @@

options = $.extend({}, default_options, options);

if (!options.hasOwnProperty('access_token')) {
$.error('jQuery.FBPagePhotos requires a valid facebook access token with correct permissions');
}

if (options.render) {
options.element = this;
}
Expand All @@ -121,8 +126,12 @@
}
};

function graph_request(id, method, success, error) {
$.getJSON("http://graph.facebook.com/" + id + "/" + method + "?callback=?")
function graph_url(id, method) {
return "https://graph.facebook.com/" + id + "/" + method;
};

function graph_request(id, method, success, error, options) {
$.getJSON(graph_url(id, method) + "?callback=?", { access_token: options.access_token })
.success(function(response) {
if (typeof response.error !== 'undefined') {
error(response.error);
Expand All @@ -137,6 +146,7 @@
page_id
, 'albums'
, function(albums) {
albums = add_album_helpers(albums);
options.albums_cb(albums, function(album) {
if ($.isPlainObject(album)) {
album = album.id;
Expand All @@ -146,9 +156,21 @@
});
}
, options.error
, options
);
};

function add_album_helpers(albums) {
return $.map(albums, function(album) {
// size is in ['thumbnail', 'small', 'album']
album.cover_photo_url = function(size) {
if (typeof(size) === "undefined") { size = 'small' }
return graph_url(album.id, 'picture') + "?type=" + size;
};
return album;
});
};

function get_photos(album_id, options) {
graph_request(
album_id
Expand All @@ -161,6 +183,7 @@
}
}
, options.error
, options
);
};

Expand Down
14 changes: 3 additions & 11 deletions src/jquery.fbpagephotos.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8b00e9b

Please sign in to comment.