Saturday, 31 August 2013

Facebook login OK but cannot connect to app

Facebook login OK but cannot connect to app

I am using Facebook JavaScript SDK.
When I click the Facebook Share button on my web page, the Facebook Login
window pops up. I typed in the username and password, logged in, and the
message "User cancelled login or did not fully authorize" showed up. I did
log in successfully, but somehow the permissions requested are not
authorized.
When I clicked the Facebook Share button again, the message "User is
logged in to Facebook, but not connected to app" showed up.
The Facebook app is created successfully with App ID & App Secret. I have
also entered the domain name under App Domains and my site under Website
with Facebook Login.
I do not know what went wrong.
Any help is appreciated!



This is the Facebook Login window, but it does not ask the user to
authorize permissions.

The code is as follows:
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'myAppId',
channelUrl : '/www.mydomain.com/channel.html',
oauth : true,
cookie : true,
status : false
});
};
function facebookLogin() {
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome!');
} else {
console.log('User cancelled login or not fully
authorized');
}
},
{scope:'email,publish_actions'});
}
function getLoginStatus() {
FB.getLoginStatus(function(response) {
if (response.status == 'connected') {
// Do something
}
return response.status;
});
}
(function(d, s, id) {
var js, fjs = d.getElementByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
.
.
.
</body>
This is the button code:
$('#fb-button').click(function() {
// Check whether login is successful.
var responseStatus = getLoginStatus();
if (responseStatus === 'connected') {
console.log("User logged in to Facebook successfully");
} else if (responseStatus === 'not_authorized') {
console.log("User is logged in to Facebook, but not connected to
app");
} else {
console.log("User is not logged in to Facebook");
facebookLogin();
}
}

No comments:

Post a Comment