FB.login () returns null on first call
I have js:
$(document).ready(function () {
$('.login-link').click(function () {
FB.login(function(response) {
console.log(response);
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(resp) {
console.log('Good to see you, ' + resp.name + '.');
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope: 'email'});
});
});
associated with <div class="login-link">FB modal login</div>
The problem is when I click the FB.login button and authorize the application, response.authResponse is null and response.status is not authorized. If I click on it again or refresh the page, it shows that the user has approved the app, but obviously I need it the first time. The code is taken from Facebook with minor modifications.
Any ideas how to solve this?
+3
source to share
1 answer
Just wanted to show a workaround for this problem in case anyone else is struggling with this.
$(document).ready(function () {
$('.login-link').click(function () {
FB.login(function(response) {
FB.getLoginStatus(function (resp) {
console.log(resp);
}, true);
}, {scope: 'email'});
});
});
I'm leaving my question open because it doesn't really answer the question of why FB.login isn't working, but at least provides a workaround.
+3
source to share