Facebook API – Asking permissions and posting to user’s wall

The Facebook API, one of the most used poorly documented API ever made. Yahoo Maps traumatized me years ago and won the first ”great service killed by poor documentation” trophy. Facebook API is now the new King in this area. The Graph API in much much better, but the documention is still below acceptable

Here is a working FBML example for your Facebook Page on how to ask permission from the user to post to his feed and sending the post after it.


function publishResult(){
getPermission();
}
function getPermission(){
Facebook.showPermissionDialog('publish_stream', permissionGranted, false,"APP_ID");

}

function permissionGranted(rights){
if(rights == {} || !rights || rights ==""){
//no rights
return false;
}
else{
//got rights
sendFeed();
}
}
function sendFeed(){
 var attachment =  {
link:    'http://www.domain.org/',
name:    'How fast are you?',
caption: 'Loremp ipsum.',
media:[{
'type': 'image',
'src': 'http://www.domain.int/path/assets/img/facebook.png',
'href': 'http://www.facebook.com/pages/linktothepage'
}]
}

var action_links = [{'text':'How fast are you?', 'href':'http://www.facebook.com/pages/linktothepage'}];

Facebook.streamPublish("helped WHO's drive for safe hospitals by reacting in "+ lastTime +" sec.", attachment, action_links, null, null, feedSent,true);
 }

function feedSent(ret,exception){

if (!ret || !ret.id) {
// Error occured
} else {
//'Post ID: ' + post_id);
}

}

Kommentoi