Facebook iframe上未运行Javascript

Facebook iframe上未运行Javascript,javascript,facebook,iframe,facebook-javascript-sdk,facebook-iframe,Javascript,Facebook,Iframe,Facebook Javascript Sdk,Facebook Iframe,我有一个django项目,它是为facebook应用程序设计的。在该项目中,邀请朋友模块在localhost中运行良好 但是,尽管它被加载到facebook应用程序中,但负责显示好友列表的javascript却无法工作。尽管库已正确加载 我不知道为什么会这样。可能是一些iframe问题。 以下是javascript代码 <script type="text/javascript"> window.fbAsyncInit = function() { FB.init({a

我有一个django项目,它是为facebook应用程序设计的。在该项目中,邀请朋友模块在localhost中运行良好

但是,尽管它被加载到facebook应用程序中,但负责显示好友列表的javascript却无法工作。尽管库已正确加载

我不知道为什么会这样。可能是一些iframe问题。 以下是javascript代码

<script type="text/javascript"> 
window.fbAsyncInit = function() {
    FB.init({appId: '460948667348013', cookie: true});

    FB.getLoginStatus(function(response) {
      if (response.status === 'connected') {
         FB.api('/me', function(response) {
           // alert('Your name is ' + response.name);
           console.log('Your name is ' + response.name);
          init();
         });
      } else if (response.status === 'not_authorized') {
        alert('the user is logged in to Facebook, but has not authenticated your app');
      } else {
        alert('the user is not logged in to Facebook.');
      }
     });  
}
    function init() {
      FB.api('/me', function(response) {
          $("#username").html("<img src='https://graph.facebook.com/" + response.id + "/picture'/><div>" + response.name + "</div>");       
          $("#jfmfs-container").jfmfs({ 
              max_selected: 15, 
              max_selected_message: "{0} of {1} selected",
              friend_fields: "id,name,last_name",
              pre_selected_friends: [1014025367],
              exclude_friends: [1211122344, 610526078],
              sorter: function(a, b) {
                var x = a.last_name.toLowerCase();
                var y = b.last_name.toLowerCase();
                return ((x < y) ? -1 : ((x > y) ? 1 : 0));
              }
          });
          $("#jfmfs-container").bind("jfmfs.friendload.finished", function() { 
              window.console && console.log("finished loading!"); 
          });
          $("#jfmfs-container").bind("jfmfs.selection.changed", function(e, data) { 
              window.console && console.log("changed", data);
          });                     

          $("#logged-out-status").hide();
          $("#show-friends").show();
      });
    }              

    $("#show-friends").live("click", function() {
        var friendSelector = $("#jfmfs-container").data('jfmfs');             
        $("#selected-friends").html(friendSelector.getSelectedIds().join(', ')); 
    });                  
    function sendRequest() {
       var friendSelector = $("#jfmfs-container").data('jfmfs');
       var sendUIDs = friendSelector.getSelectedIds().join(', '); 
       // Use FB.ui to send the Request(s)
       FB.ui({method: 'apprequests',
         to: sendUIDs,
         title: 'My Great Invite',
         message: 'Check out this Awesome App!',
       }, callback);
     }
     function callback(response) {
        // alert('callback called');
       var friendSelector = $("#jfmfs-container").data('jfmfs');
       var sendUIDs = friendSelector.getSelectedIds().join(','); 
       var uids = sendUIDs.split(',');
       var query = '';
       for(i=0;i<uids.length;i++){
        if(i==0){
            query =  query + 'to[' + i + ']=' + uids[i];
        }
        else{
        query =  query + '&to[' + i + ']=' + uids[i];
        }
       }
       console.log(query);
       if(response){
        // alert('successful');
        window.location.assign("/?"+ query)
       }
       else{
        alert('failure');
       }

     }

  </script> 

window.fbAsyninit=函数(){
init({appId:'460948667348013',cookie:true});
FB.getLoginStatus(函数(响应){
如果(response.status===“已连接”){
FB.api('/me',函数(响应){
//警报('您的名字是'+响应.名字);
console.log('您的名字是'+response.name);
init();
});
}else if(response.status===“未授权”){
警报(“用户已登录Facebook,但尚未验证您的应用程序”);
}否则{
警报(“用户未登录Facebook”);
}
});  
}
函数init(){
FB.api('/me',函数(响应){
$(“#用户名”).html(“+response.name+”);
$(“#jfmfs容器”).jfmfs({
选择的最大值:15,
max_selected_消息:“{1}个已选择中的{0}”,
好友字段:“id、姓名、姓氏”,
预选好友:[1014025367],
排除朋友:[1211122344610526078],
分拣机:功能(a、b){
var x=a.last_name.toLowerCase();
var y=b.last_name.toLowerCase();
回报率((xy)?1:0);
}
});
$(“#jfmfs container”).bind(“jfmfs.friendload.finished”,function(){
window.console&&console.log(“加载完成!”);
});
$(“#jfmfs container”).bind(“jfmfs.selection.changed”,函数(e,数据){
window.console&&console.log(“已更改”,数据);
});                     
$(“#注销状态”).hide();
$(“#显示朋友”).show();
});
}              
$(“#显示朋友”).live(“单击”,函数(){
var-friendSelector=$(“#jfmfs容器”).data('jfmfs');
$(“#选定的朋友”).html(friendSelector.getSelectedDS().join(',');
});                  
函数sendRequest(){
var-friendSelector=$(“#jfmfs容器”).data('jfmfs');
var sendUIDs=friendSelector.getSelectedIds().join(',');
//使用FB.ui发送请求
ui({method:'apprequests',
致:sendUIDs,
标题:“我的伟大邀请”,
消息:“查看这个很棒的应用!”,
},回调);
}
函数回调(响应){
//警报(“调用回调”);
var-friendSelector=$(“#jfmfs容器”).data('jfmfs');
var sendUIDs=friendSelector.getSelectedIds().join(',');
var uids=sendUIDs.split(',');
var查询=“”;

对于(i=0;i而言,问题可能是SSL问题

Facebook在几个月前做出了许多改变

你还需要不断更新Facebook开发者博客

因此,我将尝试解释一些我怀疑的事情

Facebook上的应用程序

  • 您的画布页面应
  • 1a.您的画布URL应该是

    网站

    <script type="text/javascript"> 
    window.fbAsyncInit = function() {
        FB.init({appId: '460948667348013', cookie: true});
    
        FB.getLoginStatus(function(response) {
          if (response.status === 'connected') {
             FB.api('/me', function(response) {
               // alert('Your name is ' + response.name);
               console.log('Your name is ' + response.name);
              init();
             });
          } else if (response.status === 'not_authorized') {
            alert('the user is logged in to Facebook, but has not authenticated your app');
          } else {
            alert('the user is not logged in to Facebook.');
          }
         });  
    }
        function init() {
          FB.api('/me', function(response) {
              $("#username").html("<img src='https://graph.facebook.com/" + response.id + "/picture'/><div>" + response.name + "</div>");       
              $("#jfmfs-container").jfmfs({ 
                  max_selected: 15, 
                  max_selected_message: "{0} of {1} selected",
                  friend_fields: "id,name,last_name",
                  pre_selected_friends: [1014025367],
                  exclude_friends: [1211122344, 610526078],
                  sorter: function(a, b) {
                    var x = a.last_name.toLowerCase();
                    var y = b.last_name.toLowerCase();
                    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
                  }
              });
              $("#jfmfs-container").bind("jfmfs.friendload.finished", function() { 
                  window.console && console.log("finished loading!"); 
              });
              $("#jfmfs-container").bind("jfmfs.selection.changed", function(e, data) { 
                  window.console && console.log("changed", data);
              });                     
    
              $("#logged-out-status").hide();
              $("#show-friends").show();
          });
        }              
    
        $("#show-friends").live("click", function() {
            var friendSelector = $("#jfmfs-container").data('jfmfs');             
            $("#selected-friends").html(friendSelector.getSelectedIds().join(', ')); 
        });                  
        function sendRequest() {
           var friendSelector = $("#jfmfs-container").data('jfmfs');
           var sendUIDs = friendSelector.getSelectedIds().join(', '); 
           // Use FB.ui to send the Request(s)
           FB.ui({method: 'apprequests',
             to: sendUIDs,
             title: 'My Great Invite',
             message: 'Check out this Awesome App!',
           }, callback);
         }
         function callback(response) {
            // alert('callback called');
           var friendSelector = $("#jfmfs-container").data('jfmfs');
           var sendUIDs = friendSelector.getSelectedIds().join(','); 
           var uids = sendUIDs.split(',');
           var query = '';
           for(i=0;i<uids.length;i++){
            if(i==0){
                query =  query + 'to[' + i + ']=' + uids[i];
            }
            else{
            query =  query + '&to[' + i + ']=' + uids[i];
            }
           }
           console.log(query);
           if(response){
            // alert('successful');
            window.location.assign("/?"+ query)
           }
           else{
            alert('failure');
           }
    
         }
    
      </script> 
    

    页面选项卡

  • 您的安全画布应

  • 您的页面选项卡URL应该是

  • 您的安全页面选项卡URL应该是

  • 在这种情况下,您需要为站点提供SSL证书,以便从中找到可靠但廉价的数字证书

    任何应用程序都必须在facebook上运行


    希望这对你和其他人有所帮助

    我的facebook应用现在处于沙箱模式,画布url仅为http。那么,这意味着如果画布url为https,脚本可以工作?