从页面在Facebook上共享图像


Image Sharing on Facebook from a page

我的网页有一个图像滑块。每个图像都带有一个FB共享按钮。当我单击共享按钮时,我希望特定图像与当前URL一起发布。我使用了下面的脚本:

<script type="text/javascript">
function fbShare(url, title, descr, image, winWidth, winHeight) {
var winTop = (screen.height / 2) - (winHeight / 2);
var winLeft = (screen.width / 2) - (winWidth / 2);
window.open('http://www.facebook.com/sharer.php?s=100&p[title]=' + title + '&p[summary]=' + descr + '&p[url]=' + url + '&p[images][0]=' + image, 'sharer', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width='+winWidth+',height='+winHeight);
}
</script>

但它不会选择图像,而是选择一些随机文本而不是页面正文中的文本。

请帮忙。提前谢谢。

sharer.php只接受URL作为参数,所有其他数据(标题,图像等)将来自该URL的Open Graph标签:

https://www.facebook.com/sharer/sharer.php?u=encodedurl

有关开放图形标记的更多信息:

  • http://ogp.me/
  • https://developers.facebook.com/docs/web/tutorials/scrumptious/open-graph-object