Skip to content

Instantly share code, notes, and snippets.

@guglielmino
Created June 26, 2015 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guglielmino/ce628aa750cdb98bff3d to your computer and use it in GitHub Desktop.
Save guglielmino/ce628aa750cdb98bff3d to your computer and use it in GitHub Desktop.
Post on Facebook
postOnWall: function(message, name, description, link, picture, caption, onlyOne, cookieName) {
//vedo se ho il cookie settato
var alreadyPosted = "";
alreadyPosted = leggiCookie(cookieName); // jshint ignore:line
if (alreadyPosted !== "true") {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var userId = response.authResponse.userID;
var access_token = response.authResponse.accessToken;
//vedo se ho il permesso di pubblicazione
FB.api('/me/permissions?' + access_token, function(response) {
var perms = response;
//cerco la permission publish_actions nell'array
try {
if (perms.data[0].publish_actions === 1) {
//permessi ok, invio il post sul wall
var params = {};
params['message'] = message;
params['name'] = name;
params['description'] = description;
params['link'] = link;
params['picture'] = picture;
params['caption'] = caption;
try {
FB.api('/me/feed', 'post', params, function(response) {
//se è onlyOnescrivo il cookie
if (onlyOne === true) {
var exdays = 365;
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape('true') + ((exdays === null) ? "" : "; expires=" + exdate.toUTCString()); // jshint ignore:line
document.cookie = cookieName + "=" + c_value;
}
});
} catch (e) {}
}
} catch (e) {
}
});
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment