使用FB.ui共享Facebook页面

4
我正在为我们的网站实现分享功能。 我遵循了https://developers.facebook.com/docs/javascript/quickstart/v2.4上的文档。
我们的代码如下:
var link_url = 'http://example.com/some/link';         // Works fine
link_url = 'https://www.facebook.com/<our_fan_page>';  // DOES NOT WORK

$("#btnShare").click(function(event){
  FB.ui({
    method: 'share',
    href: link_url,
  }, function(response){
    if(response && response.post_id){
      alert("Thanks for sharing");
    }else{
      alert("Oop!");
    }
  });
});

对于一些链接,比如http://example.com/some/link,它运行良好

问题是: 对于我们的FB页面链接(例如,https://www.facebook.com/[our_page_name]),它无法正常工作

当点击“分享”按钮时,FB通常会显示一个对话框。但是当我尝试通过点击“发布到Facebook”按钮时,它会显示错误信息。

Sorry, this feature isn't available right now: An error occurred while processing this request. Please try again later.

有人遇到同样的问题吗?该如何解决?


当我尝试时它可以工作,你那边还有这个问题吗? - Igy
是的,问题仍然存在。 :( - Trung
有成功了吗?这个问题还在发生。 - Uri Klar
@UriKlar:不好意思,我无法解决这个问题。 - Trung
1个回答

1

我看到这篇文章时已经有一段时间了,但我正在寻找解决方案,所以这个问题的解决方案仍然可以使我们中的一些人受益。

以下是我使用的JS代码:

function fbs_click(width, height) {
    var leftPosition, topPosition;
    //Set borders.
    leftPosition = (window.screen.width / 2) - ((width / 2) + 10);
    //Set title and status bars.
    topPosition = (window.screen.height / 2) - ((height / 2) + 50);
    var windowFeatures = "status=no,height=" + height + ",width=" + width + ",resizable=yes,left=" + leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",screenY=" + topPosition + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no";
    u=location.href;
    t=document.title;
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer', windowFeatures);
    return false;
}

这里是HTML代码:

<a href="http://www.facebook.com/share.php?u=YOURLINK" onClick="return fbs_click(500, 300)" target="_blank" title="Share This on Facebook">

正如您在这里看到的,我没有使用FB.ui(),而是使用这个技巧来解决问题。

为了避免出现以下问题:

抱歉,此功能当前不可用:处理此请求时发生错误。请稍后再试。

请确保您要分享的链接不是本地主机链接(这是我遇到该错误的唯一原因)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接