Facebook分享按钮:如何实施

时间:2012-11-04 23:11:44

标签: html facebook share facebook-apps

我正在试图弄清楚如何实现“共享”按钮,与实现方式完全一样here。我希望能够让用户将指定链接发布到他们的新闻Feed,而无需任何类型的应用权限以及可添加到其中的某些可选文本。 BuzzFeed是如何做到的? Facebook文档对我来说非常困惑,这就是为什么我自己很难实现它。如果有人能够布置需要采取的步骤,那就太棒了。我需要在HTML页面中放置什么?我需要创建一个Facebook应用程序吗?

4 个答案:

答案 0 :(得分:8)

要分享您的网页,不需要来创建Facebook应用程序。

您可以使用href = "http://www.facebook.com/sharer.php?u=<your url>"

将Facebook分享图片放在那里

Facebook的按钮也允许共享。为您的网站生成该代码的代码位于 official documentation

答案 1 :(得分:5)

编辑您要共享的页面,将这些添加到头部的元标记中。

<meta property="og:image" content="http://www. XXXX url of a jpg image you want to be displayed  on shared content has to be 200x200 pixels (make it in photoshop ect.) XXXX"/>
<meta property="og:title" content="xxxx A title you want to be dispayed in shared content xxxx"/>
<meta property="og:url" content="http://www. url of the page you want shared including the slash after .com xxx .com/"/>
<meta property="og:description" content="xxxx discription of the shared content xxx "/>

除此之外还有一个og属性列表 - http://ogp.me/

接下来,在您想要页面上的分享按钮的位置插入

<a title="xxx Share mypage.com xxx" href="http://www.facebook.com/sharer.php? u=http://www. xxx url of page you edited above xxx .com &t=xxx a title you want to use xxx" target="_blank"><img  src="http://www. xxx an image for the share button (make it in photoshop ect.)xxx" width="xx" height="xx" alt="Share"/></a>

显然取出xxx并保留“”,如果您在测试时更改上述任何内容,则可能必须转到facebook调试器并调试它,因为它有时会保留原始内容。

希望这会有所帮助

答案 2 :(得分:2)

如果您想自定义该共享页面,请尝试以下方法:

Javascript弹出示例:

var title = 'My Title';
var summary = 'This is my summary';
var url = 'http://www.mydomain.com/path/to/page';
var image = 'http://www.mydomain.com/images/myimage.png';

var fb = window.open('http://www.facebook.com/sharer.php?s=100&p[title]='+encodeURIComponent(title)+'&p[url]='+encodeURIComponent(url)+'&p[summary]='+encodeURIComponent(summary)+'&p[images][0]='+encodeURIComponent(image));
fb.focus();

答案 3 :(得分:1)

这是有效的。

HTML中的

<a href="http://www.facebook.com/sharer.php?u=<http://google.com">Facebook Link</a>

http://google.com替换为您的网址。

在PHP中,如果你想要它来拉你所在的网址:

<a href="http://www.facebook.com/sharer.php?u=<<?php echo "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>">Facebook</a>