javascript - Facebook 登录错误 (Javascript)

标签 javascript facebook authentication

我正在尝试通过 Javascript 启用 Facebook 登录到我的站点,但是当用户登录时,Facebook 弹出窗口没有关闭。相反,它显示以下消息:

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.

如果我再次点击登录按钮,一切正常。

这是我的代码:

// 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);
}

最佳答案

你应该尝试这样的事情:

https://gist.github.com/3370553

或者您可以使用 JS API 中的“FB.login”替换 AuthorizeFacebook

关于javascript - Facebook 登录错误 (Javascript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11890500/

相关文章:

facebook - 如何识别 Facebook User-Agent

Facebook Javascript SDK : Why do I need a 'app-id' when invoking FB. 初始化()?

php - 单独的后端 (Symfony2) 和前端 (AngularJS) REST - 如何进行身份验证

javascript - 使用 Snap.svg 创建多行文本

javascript - 添加 EmojiOne 区域后字符计数器中断

Javascript 代码在启动时运行一次(addEventListener 不起作用)

node.js - 授权。尝试查询 Azure 上的 PostgreSQL 时出错

javascript - AJAX 仅加载和返回有限数量的对象

java - 使用 Facebook SDK 和 ParseFacebookUtils 登录时出现 NullPointerException

authentication - 无法使用Golang使用服务帐户凭据访问Google Spreadsheets