我正在试着自定义facebook分享。我正在使用一个很棒的应用程序:https://github.com/kni-labs/rrssb来做这个。我尝试过facebook提供的meta标签,但它对我不起作用。但是使用java-script,它还是可以工作的。
<ul class="rrssb-buttons clearfix">
<li class="rrssb-facebook">
<a href="https://www.facebook.com/sharer/sharer.php?u={{ request.build_absolute_uri }}" class="popup">facebook-share</a>
</li>
</ul>
<script type="text/javascript">
jQuery(document).ready(function ($) {
$('.rrssb-buttons').rrssb({
// required:
title: 'email',
url: 'http://www.reddit.com/',
});
});
</script>这显示了reddit的图片,reddit的描述等。所以我想我应该把用户尝试分享的域名放在url里,而不是reddit的url里。我用谷歌搜索了一下,我看到一些人是如何在url...so中发布图片和描述的。我的问题是,如何将用户试图分享的url放在url中?我如何将图像放在那里?
发布于 2016-03-31 14:45:26
您可以使用window.location.href作为URL来使用当前页面的URL。要指定镜像,只需在初始化rrssb时添加image密钥即可。就像你看到rrssb.js的源代码一样,你会看到它在初始化时支持哪些参数。它们是
// Settings that $.rrssb() will accept.
var settings = $.extend({
description: undefined,
emailAddress: undefined,
emailBody: undefined,
emailSubject: undefined,
image: undefined,
title: undefined,
url: undefined
}, options );因此您的代码将更改为
jQuery(document).ready(function ($) {
$('.rrssb-buttons').rrssb({
title: 'email',
url: window.location.href,
image: your_image_url
});
});编辑(仅使用URL,而不是图像):
我不认为你可以在facebook或twitter上使用图片。如果你看到rrssb.js的源代码,你会发现只有网址是分享给facebook的。URL和描述将共享到twitter。因此,一些设置被分享给一些社交网站。
同样在rrssb.js的readme.md中,如果你看到facebook分享示例
<li class="rrssb-facebook">
<!-- Replace with your URL. For best results, make sure you page has the proper FB Open Graph tags in header: https://developers.facebook.com/docs/opengraph/howtos/maximizing-distribution-media-content/ -->
<a href="https://www.facebook.com/sharer/sharer.php?u=http://kurtnoble.com/labs/rrssb/index.html" class="popup">
<span class="rrssb-icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 29 29"><path d="M26.4 0H2.6C1.714 0 0 1.715 0 2.6v23.8c0 .884 1.715 2.6 2.6 2.6h12.393V17.988h-3.996v-3.98h3.997v-3.062c0-3.746 2.835-5.97 6.177-5.97 1.6 0 2.444.173 2.845.226v3.792H21.18c-1.817 0-2.156.9-2.156 2.168v2.847h5.045l-.66 3.978h-4.386V29H26.4c.884 0 2.6-1.716 2.6-2.6V2.6c0-.885-1.716-2.6-2.6-2.6z"/></svg></span>
<span class="rrssb-text">facebook</span>
</a>
</li>在评论中你可以看到声明
为获得最佳效果,请确保您的页面在页眉中有正确的FB Open Graph标签
这意味着,facebook将从页面标题部分的FB Open Graph meta标签中挑选图像信息。
https://stackoverflow.com/questions/36325745
复制相似问题