我正在运行一个与此非常相似的错误:Facebook Login API HTTPS Issue .
我有一个网站使用facebook认证,facebook登录没问题。但是 Facebook 点赞按钮在点击时出现问题(在 Chrome、Safari、Firefox、OSX 中测试失败),错误消息为:
Blocked a frame with origin "https://www.facebook.com" from accessing a
frame with origin "http://static.ak.facebook.com". The frame requesting
access has a protocol of "https", the frame being accessed has a protocol
of "http". Protocols must match.
我到处搜索,没有找到任何解决方案。
似乎当点击赞按钮时,它会从 https://facebook.com 弹出一个框架。回调并尝试请求 http://static.ak.facebook.com从而导致协议(protocol)不匹配?!
这是我放在 <body>
之后的内容标签
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : 'appid', // App ID from the app dashboard
channelUrl : '//mydomain/channel.html', // Channel file for x-domain comms
status : true, // Check Facebook Login status
xfbml : true // Look for social plugins on the page
});
// Additional initialization code such as adding Event Listeners goes here
};
// 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/zh_TW/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
channel 文件位于http://mydomain/channel
<script src="//connect.facebook.net/zh_TW/all.js"></script>
下面是我如何使用点赞按钮
<div class="fb-like" data-href=url data-send="true" data-width="450"
data-show-faces="true"></div>
真的需要帮助,拜托!
最佳答案
在您的第一个脚本标签中,您可以明确告诉 Facebook 使用 HTTPS...
添加行:
FB._https = (window.location.protocol == "https:");
将它添加到 FB.init 函数调用之前,就在注释下方或代替注释:
// init the FB JS SDK
这将确保 Facebook 的服务器通过 https 加载任何所需的库。
希望这对您有所帮助。
关于Facebook 点赞按钮 https 问题 : protocol mismatch from http and https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17164251/