2012-01-20 97 views

回答

4

我一直使用此设置来处理登录状态和权限:

function getPerms() { 
    FB.login(function(response) { 
     if (response.authResponse) { 
      //user has granted permissions 
     } 
    }, {scope:"email, ..."}); 
} 

function getStatus() { 
    FB.getLoginStatus(function(response) { 
     if (response.status === "connected") { 
      //user has granted permissions 
     } else { 
      getPerms(); 
     } 
    }); 
} 

您还必须包括all.js并致电FB.init(...)

0

这里是你如何能做到这一点:

FB.init(
    { 
     "appId"  : xxxxxxxxxx, 
     "status"  : true, 
     "cookie"  : true, 
     "xfbml"  : true, 
     "oauth"  : true 
    }); 

    FB.Event.subscribe('auth.authResponseChange', function(response) 
    { 
     // need to wait few seconds for fb login status to work in FireFox 
     setTimeout('window.location.reload()', 3000); 
    }); 


function fbConnect(){ 
    FB.getLoginStatus(function(response) { 
     if (response.authResponse){ 
     FB.login(function(response) 
     { 
      if (response.authResponse) { } 
      else 
      { 
       //console.log('User cancelled login or did not fully authorize.'); 
      } 

     }, {"scope":"email,manage_pages"}); 
     } 
    }); 
} 

你需要调用fbConnect()功能。

另外,还要确保你有这些低于<body>标记您的网页上:

<div id="fb-root"></div> 
<script src="//connect.facebook.net/en_US/all.js"></script> 
0
  1. 您需要提供我的代码,以获得更好的/准确的答案
  2. 最有可能你没有升级你的代码使用OAuth 2.0,请参阅基于上面的链接here
  3. ,使用scope代替perms
  4. 使用response.authResponse代替response.session
  5. 欢迎来到Stackoverflow!
相关问题