我上周启动了一个应用程序,并注意到在Chrome中,只有画布的高度并不总是调整的。我花了几个小时研究这些问题,并注意到我有时会出现以下错误。
Unsafe JavaScript attempt to access frame with URL https://apps.facebook.com/tabletr/ from frame with URL
http://static.ak.facebook.com/connect/canvas_proxy.php?version=3#behavior=p&method=getPageInfo¶ms=%7B%22channelUrl%22%3A%22https%3A%2F%2F%2Fs static.ak.fbcdn.net%2Fconnect%2Fxd_proxy.php%3Fversion%3D3cb%3Df3782154e%26origin%3Dhttps%253A%252F%252Ftabletr.herokuapp.com%252Ff2951037b%26relationship%3Top.frames%255Biframe_canvas_fb_https%255D%26transport%3Postmessage%22%2C%22frame%22%3A22iframe_canvas_filb_https%22%7D&relationship=top。域、协议和端口必须匹配。
现在,我对编程略知一二,推断出这可能是由于https
和http
可以互换使用。我(有时)会在Facebook上"打开"安全浏览时出错,而从不在"关闭"时出错。
但我发现真正奇怪的是,当通过HTTPS浏览时,这个问题偶尔会发生。我仍然没有发现任何即将出现的问题模式,也没有发现我的代码按预期工作。我知道这里有一些关于这个话题的帖子,我尝试了很多变通方法,但似乎没有一个能解决我的问题。这是我的部分代码-
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<myid>', // App ID
channelUrl : '//tabletr.herokuapp.com/channel.php', // Channel File
status : false, // Check login status
cookie : true, // Enable cookies to allow the server to access the session
xfbml : false // Parse XFBML
});
// Additional initialization code here
FB.Canvas.setSize({ height: 1200 });
};
// If I comment out this function I don't get any unsafe URL errors
// anymore. I'm guessing that the include of the JavaScript code either
// fails to use the right protocol or is faulty in its implementation
// by Facebook. My money is on the former.
(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";
js.src = "//tabletr.herokuapp.com/js/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
我该如何解决这个问题?老实说,我不在他们中间。也许我的通道文件实现错误?
更新的代码
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<myid>', // App ID
channelUrl : '//tabletr.herokuapp.com/channel.php', // Channel File
status : false, // Check login status
cookie : true, // Enable cookies to allow the server to access the session
xfbml : false // Parse XFBML
});
// Additional initialization code here
FB.Canvas.setSize({ height: 1200 });
};
// If I comment out this function I don't get any unsafe URL errors
// anymore. I'm guessing that the include of the JavaScript code either
// fails to use the right protocol or is faulty in its implementation
// by Facebook. My money is on the former.
(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";
//js.src = "//tabletr.herokuapp.com/js/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
我已经基于Stack OVerflow问题更新了我的代码通过HTTPS加载非安全项目的Facebook JavaScript SDK-然而,这还没有解决问题。我在2012-01-19遇到了以下错误报告,其中显示了我面临的相同症状。但愿Facebook很快就能解决这个问题!
https://developers.facebook.com/bugs/192507854181725?browse=search_4f2bbd593f8798794293016
//js.src = "//connect.facebook.net/en_US/all.js";
js.src = "//tabletr.herokuapp.com/js/all.js";
看起来您已将http://connect.facebook.net/en_US/all.js
复制到本地服务器,作为https://tabletr.herokuapp.com/js/all.js
。
http://connect.facebook.net/en_US/all.js
和https://connect.facebook.net/en_US/all.js
的差异显示了一些分别硬编码为"http"one_answers"https"的URL。如果你想在本地复制这些,你必须像Facebook一样托管两个独立的版本。
但我建议你只需指向Facebook的官方脚本,这样你就不必一直同步它。
当您错误地配置fb应用程序时,也可能发生这种情况,请检查接下来的三个步骤
1-确保你的facebook应用程序的redirect_uri
没有丢失
转到您的应用程序>>设置>>高级>>安全。然后设置CCD_ 8
2-确保您的应用允许登录Client OAuth Login
和Embedded browser OAuth Login
转到您的应用程序>>设置>>高级>>安全。然后为
Client OAuth Login
和Embedded browser OAuth Login
选择"是"
3-别忘了配置你的应用程序以接受来自你的网站的登录
转到您的应用程序>>设置>>添加平台>>网站。然后用您的域设置
Site URL
。
完全可能。
您的错误消息显示:
域、协议和端口必须匹配
您正在使用中包含的脚本访问帧
https://apps.facebook.com/tabletr/
来自具有URL 的帧
http://static.ak.facebook.com/connect/canvas_proxy.php?。。。
因此,这看起来确实像是http/https不匹配。我不认为这会延伸到子域,但这可能会有问题。
但这是你的代码,还是框架的代码?基本上,您需要确保这两种协议在安全或常规浏览场景中匹配。
Facebook已经承认这是一个错误,并将其分配给了一名工程师。您可以在跟踪进度https://developers.facebook.com/bugs/192507854181725?browse=search_4f2bbd593f8798794293016