Facebook共享APi不起作用

Facebook share APi not working

本文关键字:不起作用 APi 共享 Facebook      更新时间:2023-09-26

我尝试使用此代码共享页面

FB.ui(
 {
  method: 'share',
  href: 'https://developers.facebook.com/docs/'
}, function(response){})

运行此初始化代码后

FB.init({
    appId      : 'my-app-id',
    status     : true,
    cookie     : true,
    xfbml      : true,
    version    : 'v2.1'
});

它仅在我第一次按下页面上的按钮时才有效。 下次我尝试单击调用FB.UI函数的按钮,我在控制台中收到此错误

未捕获的安全错误:阻止原点为"https://s-static.ak.facebook.com"的帧访问原点为"https://www.mywebsite.com"的帧。协议、域和端口必须匹配。

如果我在隐身模式下运行页面,一切正常。

我尝试了网站上提供的许多解决方案,但无法解决问题有人有建议吗?

我发现FB.getLoginStatus函数不能与FB.ui函数很好地配合使用。所以我通过创建打开共享窗口而不是使用 FB.ui 函数的函数来解决问题

function facebook_share(link){
    var left = (screen.width/2)-(520/2);
    var top = (screen.height/2)-(430/2);
    window.open("https://www.facebook.com/sharer/sharer.php?u=="+link, "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top="+top+", left="+left+", width=520, height=430");
}