javascript 将自定义文本传递给新的 Facebook Sharer 按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23048197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Passing custom text to new Facebook Sharer button
提问by mdv
I need to pass some AngularJS variables from my application to the new Facebook sharer button, I'm using:
我需要将一些 AngularJS 变量从我的应用程序传递到新的 Facebook 共享器按钮,我正在使用:
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/es_LA/all.js#xfbml=1&appId=1438439249728371";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
And this:
还有这个:
<div class="fb-share-button" data-href="http://mySite" data-type="button"> </div>
Where can I place my custom text to share in the dialog?
在哪里可以放置自定义文本以在对话框中共享?
Thank you!
谢谢!
回答by Sahil Mittal
Sharerwont allow that. It'll fetch the og tags from the link and fill the contents in the dialog.
共享者不会允许的。它将从链接中获取 og 标签并填充对话框中的内容。
If you want to add cutomized description/picture/caption you should instead use Feed Dialog.
如果你想添加自定义描述/图片/标题,你应该使用Feed Dialog。
You can use the direct URL to invoke feed dialog:
您可以使用直接 URL 来调用提要对话框:
https://www.facebook.com/dialog/feed?
app_id=1438439249728371
&display=popup
&caption={caption}
&link={link-to-share}
&description={description}
&redirect_uri={redirect-url-to-your-site}
You can check all available parameters here
您可以在此处查看所有可用参数
回答by Ivan Belchev
If you use the Facebook SDK for JavaScript you have to use the parameter quote
如果您使用 Facebook SDK for JavaScript,则必须使用参数引用
FB.ui({
method: 'share',
display: 'popup',
href: window.location.href,
quote: "Your Custom Text"
}, function(response){});