Facebook Login Error (Javascript)

I'm trying to enable Facebook login to my site via Javascript but when the user logs in, the Facebook popup doesn't closes. Instead it shows the following message:

An error may have occurred as part of the login process. You can close this window and try returning to the application, though it may ask you to login again. This is likely due to a bug in the application.

If I click again on the login button, everything works fine.

This is my code:

// Load the SDK Asynchronously
(function(d){
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
    if (d.getElementById(id)) {return;}
    js = d.createElement('script'); js.id = id; js.async = true;
    js.src = "//connect.facebook.net/en_US/all.js";
    ref.parentNode.insertBefore(js, ref);
}(document));

// Init the SDK upon load
window.fbAsyncInit = function() {
    var doLogin = function (response) {
        url = '//'+window.location.hostname+'?        access_token='+response.authResponse.accessToken;

        window.top.location = url;
    };

    FB.init({
        appId      : 'MY_APP_ID', // App ID
        status     : true, // check login status
        cookie     : true, // enable cookies to allow the server to access the session
        xfbml      : true, // parse XFBML
        oauth      : true,
        channelUrl : '//'+window.location.hostname+'/static/html/channel.html'
    });

    FB.Event.subscribe('auth.login', function(response) {
        doLogin(response);
    })

    FB.getLoginStatus(function(response) {
        if (response.status == 'connected') {
            doLogin(response);
        }
    }, true);
}

Answers


You should try something like this:

https://gist.github.com/3370553

Or you could replace AuthorizeFacebook with "FB.login" from the JS API


Need Your Help

How to delete user-defined build settings in Xcode 4.3.1

xcode4 build-settings

I have created several user-defined build settings in Xcode 4.3.1. I no longer need these settings and want to delete them, but there doesn't seem to be a way to delete them!