I'm trying to make a simple facebook app, but for the authorization, it seems that it's always blocked by a popup-blocker. My code is thus:
FB.init({
appId : THEAPPPIDDDD,
status : true,
cookie : true,
xfbml : true,
});
FB.login(function(response) {
if (response.authResponse) {
FB.api('/me', function(response) {
FB.logout(function(response) {
console.log('Logged out.');
});
});
} else {
console.log('User did not authorize.');
}
});
Any help would be greatly appreciated... thanks
Attention: Viewing Facebook without an Account, you can simply bypass the Facebook “Log In or Sign Up” prompt by clicking on the “Not Now” link at the bottom of the page.
In the App Dashboard, choose your app and scroll to Add a Product Click Set Up in the Facebook Login card. Select Settings in the left side navigation panel and under Client OAuth Settings, enter your redirect URL in the Valid OAuth Redirect URIs field for successful authorization.
I aware that this question is a possible duplicate of another question: Stop the facebook popup blocker I am reposting this to help Dave Zhang. I have adapted this code for one of my site. In the following code, replace the YOUR_APP_ID and your website url, then the Facebook login will be popup-less.
//Javascript
var uri = encodeURI('http://example.com');
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
window.location.href=uri;
} else {
window.location = encodeURI("https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri="+uri+"&response_type=token");
}
});
This will just redirect directly instead of opening a pop-up.
You should initiate your login code on click of some button. As a good practice while dealing with FB, the login process should always be initiated by user.
Call your code on click of a button and it should FIX your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With