2011-10-14 19 views
0

我在Facebook上的应用程序使用JavaScript SDK。当用户导航到我的应用程序页面并转到我的应用程序时,弹出窗口会要求他们授权应用程序。这很好。但是,如果他们授权应用程序,然后再回到它,另一个弹出窗口(我认为是另一个授权窗口)将很快打开然后关闭。即使已经授权,授权窗口重新打开,然后快速关闭。如何避免这种情况?

我的代码是做什么的?代码如下。

<div id="fb-root"></div> 
<script> 
    window.fbAsyncInit = function() { 
    FB.init({ 
     appId  : '221953271200525', // App ID 
     channelURL : '//www.vidjahgames.com/fall/channel.html', // Channel File 
     status  : true, // check login status 
     cookie  : true, // enable cookies to allow the server to access the session 
     oauth  : true, // enable OAuth 2.0 
     xfbml  : true // parse XFBML 
    }); 

    // Additional initialization code here 


FB.login(function(response) { 
    if (response.authResponse) { 
    console.log('Welcome! Fetching your information.... '); 
    FB.api('/me', function(response) { 
     console.log('Good to see you, ' + response.name + '.'); 

    }); 
    } else { 
    console.log('User cancelled login or did not fully authorize.'); 
    } 
}, {scope: 'email'}); 


    }; 

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

回答

0

的FB.login使弹出出现,所以你首先应该知道,如果用户登录,如果没有让登录弹出显示:

FB.getLoginStatus(function(response) { 
    if (response.session) { 
    // A user has logged in, and a new cookie has been saved 
    FB.api('/me', function(response) { 
     _userName = response.name; 
     alert("hello"+_userName); 
    }.bind(this)); 
} else { 
    FB.login(function(response) { 
     // the rest of your code here... 
    } 

} 
});