Created
June 26, 2015 08:23
-
-
Save guglielmino/ce628aa750cdb98bff3d to your computer and use it in GitHub Desktop.
Post on Facebook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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