FB.getLoginStatus无法使用https

时间:2012-06-21 14:59:17

标签: php facebook facebook-javascript-sdk

我知道这是一个该死的简单问题,但我没有找到任何解决方案。当我的应用程序由https://安全浏览的人打开时,FB.getLoginStatus不会触发。首先我使用了FB._HTTPS,现在它正在运行FB已删除了._的所有元素。那么如何让FB.getLoginStatushttps://合作?我的代码看起来像

 <script src="//connect.facebook.net/en_US/all.js"></script>
 <script>
        console.log("layout");
        //FB._https = (window.location.protocol == "https:");
        //FB._https = true;
        console.log("fb https true");
        FB.init({
            appId : '<?php echo $this->appId; ?>',
            channelUrl : '//<?php echo $_SERVER["HTTP_HOST"]; ?>/static/content/channel.php',
            status : true, // check login status
            cookie : true, // enable cookies to allow the server to access the session
            xfbml : true // parse XFBML
        });
   </script>
 function PostAction(custom_action)
 {
     console.log('outside of fbgetlogin');
     FB.getLoginStatus(function(response)
    {
        console.log("in getlogin status");
        if (response.authResponse) {
            fbcallBack(response);
        } else {
            FB.login(fbcallBack, {scope:'publish_stream'});
        }
    });
}

我的channel.php文件包含

  <?php
 $cache_expire = 60*60*24*365;
 header("Pragma: public");
 header("Cache-Control: max-age=".$cache_expire);
 header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$cache_expire) . ' GMT');
 ?>
   <script src="//connect.facebook.net/en_US/all.js"></script>

我的PostAction功能在onclick事件时触发。 FB.getLoginStatus is triggered when user is on的http:// bit not triggered when user is on的https://`

任何机构都可以告诉我如何使用https://?

使getloginstatus工作

详细更新问题

让我详细告诉你这个问题。我已经实现了facebook的Action动词。我已经实现了三个动词。想要,拥有并推荐。现在,我想在用户点击该按钮时检查用户的登录状态。所以当你看到我在自定义按钮上的onclick事件中调用PostAction()函数时。现在在那个事件我想检查用户是否登录。此函数存在于不同的文件中。并且init函数存在于may布局文件中(用于泛化的观点)。现在我该如何处理这种情况?

1 个答案:

答案 0 :(得分:1)

您将需要使用异步加载并使用in。

调用getLoginStatus
 <div id="fb-root"></div>
<script>
      window.fbAsyncInit = function() {
        FB.init({
    appId  : '135669679827333',
    status : true, // check login status
    cookie : true, // enable cookies to allow the server to access the session
    xfbml  : true, // parse XFBML
    channelUrl : 'https://anotherfeed.com/emo/channel.html', // channel.html file
    oauth  : true // enable OAuth 2.0
        }); 
  //      
  FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    // the user is logged in and has authenticated your
    // app, and response.authResponse supplies
    // the user's ID, a valid access token, a signed
    // request, and the time the access token 
    // and signed request each expire
    var uid = response.authResponse.userID;
    var accessToken = response.authResponse.accessToken;
  } else if (response.status === 'not_authorized') {
    // the user is logged in to Facebook, 
    // but has not authenticated your app
  } else {
    // the user isn't logged in to Facebook.
  }
 });
//          
        });
      };
  // Load the SDK Asynchronously
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>