FB好友选择器框架在https中,不能与http中的托管页面交互


FB friend-selector frame is in https and cannot interact with hosting page in http

我在一个网站上实现了一个邀请你的朋友的功能。
最近它停止工作了(由于"稳定"的Facebook图形API的持续愉悦…)
我试着把我的头从这个没有运气。
当我与好友选择器框架交互时,我得到以下错误:

阻止了一个原点为https://www.facebook.com的帧访问原点为"http://myDomain.com"的帧。请求帧访问有一个"https"协议,被访问的帧有一个http协议。协议必须匹配。

我的web-app确实是在HTTP而不是https上,但是这个错误是新的,因为这个功能在过去工作过。

这是我用来打开朋友选择器框架的代码:

  function sendRequestViaMultiFriendSelector() {
    window.fbAsyncInit();
    FB._inCanvas = true;
    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
            FB.ui({method: 'apprequests',
                message: 'my message to my friends goes here'
            }, function(response) {
                console.log('requestCallback');
                console.log('request: '+response.request);
                console.log('to: '+response.to);
                //write response values to DB goes here... 
            });
            var uid = response.authResponse.userID;
            var accessToken = response.authResponse.accessToken;
        } else {
            console.log('sendRequestViaMultiFriendSelector, not connected');
            FB.login(function(response) {
                if (response.authResponse) {
                    console.log('starting again');
                    sendRequestViaMultiFriendSelector();
                } else {
                    console.log('User cancelled login or did not fully authorize.');
                    on_fb_fail();//...
                }
            }, {scope: "email,"+
                        "user_about_me,"+
                        "publish_stream"});
        }
    });
} 
这是我用来初始化FB api的代码
 console.log('>> window.environment: '+window.environment);
window.fbAsyncInit = function() {
    console.log('window.fbAsyncInit, window.fb_inited: '+window.fb_inited);
    if(window.fb_inited === false){
    console.log('executing window.fbAsyncInit...');
    //if (navigator.appName.indexOf("Microsoft") != -1) {
    //if(/msie/gi.test(navigator.userAgent) ){
    if(navigator.appName === 'Microsoft Internet Explorer'){
        window.fb_inited = true;    
        FB.init({
            appId                : 'MY_APP_ID', // App ID
            status               : true, // check login status
            cookie               : true, // enable cookies to allow the server to access the session
            xfbml                : true,  // parse XFBML
            oauth                : true,
                    frictionlessRequests : true
        });
    } else {
        window.fb_inited = true;
        FB.init({
            appId                : 'MY_APP_ID', // App ID 
            channelUrl           : 'http://www.myDomain.com/channel.cfm', // Channel File
            status               : true, // check login status
            cookie               : true, // enable cookies to allow the server to access the session
            xfbml                : true,  // parse XFBML
            oauth                : true,
                    frictionlessRequests : true
        });
    }
    console.log('window.fb_inited: '+window.fb_inited);
    }
// Additional initialization code here
};
(function(d, s, id){
    window.fb_inited = false;
    console.log('Loading FB JS-SDK asynchronously...');
    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'));

this is my channel.cfm

<cfsilent>
    <cfparam name="url.localeCode" default="en_US" />
    <cfset cacheExpire = 60 * 60 * 24 * 365 />
    <cfheader name="Pragma" value="public" />
    <cfheader name="Cache-Control" value="maxage=#cacheExpire#" />
    <cfheader name="Expires" value="#getHttpTimeString(dateAdd('d', now(), 365))#">
</cfsilent>
<cfoutput>
    <script src="//connect.facebook.net/#url.localeCode#/all.js"></script>
</cfoutput>

这是一个快速cf端口从一个通道。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>

将非常感谢任何想法我听说Facebook并没有同步更新他们的参考,所以我很乐意使用他们的API。我基于这些链接的脚本:FB。Init - https://developers.facebook.com/docs/reference/javascript/FB好友请求- https://developers.facebook.com/docs/reference/dialogs/requests/

我添加了这两行代码来打破iFrame,它解决了异常

if (top.location!= self.location){
  top.location = self.location
}

这解决了不同协议的问题…