facebook oauth对话框中的问题

时间:2012-10-15 04:42:37

标签: javascript facebook

我已经使用javascript SDK在我的网站上集成了Facebook登录..一切正常,除了auth对话框,它只为用户显示一次。下次用户登录时重定向而不显示auth对话框。我希望每次用户登录时都显示auth对话框。 这是我正在使用的代码

window.fbAsyncInit = function() {
        FB.init({
        appId  : 'xxxxxxxx',
        status : true, 
        cookie : true, 
        xfbml  : true, 
        oauth  : true 
        });
        if (window!=window.top) {
            FB.Canvas.setAutoResize();
        };
        FB.getLoginStatus(function(response) {
            if (response.authResponse) {                
               window.FBlogin = function(){
                    FB.login(function(response) {
                        if (response.authResponse) {                         
                    FB.api('/me', function(response) {
                    console.log('Good to see you, ' + response.name + '.');
                     var query = FB.Data.query('select name,username, email, hometown_location, sex, pic_square from user where uid={0}', response.id);
                     query.wait(function(rows) {
                     //document.getElementById('name').innerHTML = '<img src="' + rows[0].pic_square + '" alt="" />';
                        var name=rows[0].name;
                        var email=rows[0].email;
                        var uid=response.id;
                        var username=rows[0].username;
                        var pic=rows[0].pic_square;                    
                     });
    });

                        } 
                        else {
                            alert("error");

                        }                       
                    }, {scope: 'email'});                                       
                };           
            }
            else {

                var authbox = document.getElementById('FBauth');
                authbox.innerHTML="";
                var a = document.createElement('a');
                a.setAttribute("href","javascript:void();");
                a.setAttribute("onclick","FBlogin();");              
                authbox.appendChild(a);
                window.FBlogin = function(){
                    FB.login(function(response) {
                        if (response.authResponse) {
                        FB.api('/me', function(response) {
                        console.log('Good to see you, ' + response.name + '.');
                     var query = FB.Data.query('select name,username, email, hometown_location, sex, pic_square from user where uid={0}', response.id);
                     query.wait(function(rows) {
                        var name=rows[0].name;
                        var email=rows[0].email;
                        var uid=response.id;
                        var username=rows[0].username;
                        var pic=rows[0].pic_square;                     
                     });
                  });                           
                } 

                    }, {scope: 'email'});
                };                
            }           
        });
 FB.Event.subscribe('auth.login', function () {
         FB.api('/me', function(response) {
                    console.log('Good to see you, ' + response.name + '.');
                     var query = FB.Data.query('select name,username,email, hometown_location, sex, pic_square from user where uid={0}', response.id);
                     query.wait(function(rows) {
                        var name=rows[0].name;
                        var uid=response.id;
                        var email=rows[0].email;
                        var username=rows[0].username;
                        var pic=rows[0].pic_square;
                        var page='';
                        $('<input />').attr({'type':'hidden', 'id':'fbname','value':email}).appendTo('#fbaccess');
                  });
               })         
         });

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

1 个答案:

答案 0 :(得分:0)

  

一切正常,除了auth对话框,该对话框只显示一次用户。下次用户登录时重定向而不显示auth对话框。

如果用户已连接到您的应用并已提供所有请求的权限 - 那么这就是预期的行为。

在这种情况下再次调用FB.login将打开弹出窗口,并立即再次关闭它。

  

我希望每次用户登录时都显示auth对话框。

我无法看到应用程序以这种方式运行的好处。

无论如何,有一个参数可以显式请求用户重新进行身份验证:auth_type = reauthenticate。这将强制用户重新输入密码。有关详细信息,请参阅https://developers.facebook.com/docs/authentication/reauthentication/#client-side

但我不确定这是你真正想要的。

另一种方法是通过您的应用删除权限,然后通过scope参数再次请求它们。这应该再次打开Auth对话框。有关详细信息,请参阅https://developers.facebook.com/docs/reference/api/user/#permissions

相关问题