Skip to content

Instantly share code, notes, and snippets.

@MioGreen
Last active August 29, 2015 14:01
Show Gist options
  • Save MioGreen/fa1fef5d73fecfe23fa7 to your computer and use it in GitHub Desktop.
Save MioGreen/fa1fef5d73fecfe23fa7 to your computer and use it in GitHub Desktop.
Facebook browser sharing
function FacebookShareStrategy(user, $http) {
var url,
userId = user.id,
userToken = user.token;
this.share = function (message, photos, htmlPresentation) {
url = 'https://graph.facebook.com/' + userId +
'/feed?callback=JSON_CALLBACK&message=' + message +
picture(photos) + presentation(htmlPresentation) +
'&access_token=' + userToken;
return $http.post(url).
then(function (data) {
return data;
},function () {
console.log('Could not get data');
});
};
function picture(photos) {
var data = '';
if (photos[0]) {
data = '&picture=' + photos[0].src;
}
return data;
}
function presentation(link) {
var data = '&link=' + link;
return data;
}
}
this.shareOnFb = function(message, photos, htmlPresentation, socialOptions, observer) {
new FacebookShareStrategy(socialOptions, $http)
.share(message, photos, htmlPresentation)
.then(function(){
observer.onSharedViaFb();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment