Facebook在HTTPS中浏览时通过HTTP加载资产

时间:2012-02-13 19:53:36

标签: https facebook-javascript-sdk facebook-canvas

我做了很多谷歌搜索,但没有找到这个问题的答案。

我已经按照Facebook文档来实现Facebook JS SDK。这是我页面上的代码段

<script>
    window.fbAsyncInit = function() {
        FB.init({
            appId  : 'xxxxxxxxxxxxx',
            status : true, // check login status
            cookie : true, // enable cookies to allow the server to access the //session
            xfbml  : true, // parse XFBML
            oauth :true // Enable oauth 2.0
        });
        FB.Canvas.setAutoResize(); //set size according to iframe content size
    };

    // 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>

除了一个文件外,这种方法效果很好: http://static.ak.facebook.com/connect/canvas_proxy.php

all.js 通过HTTPS加载就好了。但Facebook仍然通过常规HTTP加载canvas_proxy.php:

http://static.ak.facebook.com/connect/canvas_proxy.php?version=3#behavior=p&method=setSize&params=%7B%22height%22%3A714%2C%22width%22%3A1100%2C%22frame%22%3A%22iframe_canvas%22%7D

这是为什么?我好像做得对。 HTTPS用户因访问该网址而访问我的网页时会收到安全警告。

1 个答案:

答案 0 :(得分:0)

在FB.init调用之前尝试设置FB._https = true。这将照顾canvas_proxy.php。

最初在Facebook JavaScript SDK over HTTPS loading non-secure items

中详述的解决方案
相关问题