2

我知道这是一个该死的简单问题,但我还没有找到任何解决方案。当我的应用程序被具有安全浏览功能的人打开时,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 onhttp:// bit not triggered when user is onhttps://`

任何人都可以告诉我如何使 getloginstatus 与 https:// 一起工作吗?

详细更新问题

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

4

1 回答 1

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>
于 2012-06-21T15:07:10.500 回答