I am writing a simple JS program to post on FB.
The login script looks something like below:
indow.fbAsyncInit = function() {
FB.init({
appId: '1469527639#######',
version : 'v2.0',
xfbml : true,
status : true,
cookie : true
});
// fetch the status on load
FB.getLoginStatus(loginChecker);
};
(function(d, s, id){
var js;
var fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function loginChecker(response){
if(response.status === "connected"){
console.log('This app is already authorized');
} else if(response.status === "not_authorized") {
console.log('This app is not authorized');
} else {
console.log('user is not logged into fb');
FB.login(function(){}, { scope: 'publish_actions', return_scopes: true});
}
}
The above script doesn't exactly perform as per expectation. It does display the Facebook login box, however after I enter my credentials, it does not ask for permission to post on wall.
I have another function that is suppose to post a message on the user's wall once the user is logged in. But since the above script does not ask for these permissions, i am unable to post.
As per Facebook documentation, i should be asking for permissions using
{ scope: 'publish_actions', return_scopes: true}
I am already doing this.
The button that posts on the user's wall is simple :
$('#postit').bind('click', function(){ var messageToPost = document.getElementById("messageArea").value;
FB.api('/me/feed','post',{message: messageToPost},function(response){
if(!response || response.error){
console.log('There was a issue in posting your emssage');
} else {
console.log(response.id);
}
});
});