![](/img/trans.png)
[英]Facebook-Share with open graph custom Title, Image, Description not showing (Magento 2)
[英]Facebook custom share button not showing description
我正在使用以下JS代碼在Facebook上共享。
function openFbPopUp() {
var fburl = 'http://54.251.121.6/cnc/cupcakes-n-chai-side-table';
var fbimgurl = 'http://imageURL';
var fbtitle = 'Your title';
var fbsummary = "This is the description blah blah blah";
var sharerURL = "http://www.facebook.com/sharer/sharer.php?s=100&p[url]=" + encodeURI(fburl) + "&p[images][0]=" + encodeURI(fbimgurl) + "&p[title]=" + encodeURI(fbtitle) + "&p[summary]=" + encodeURI(fbsummary);
window.open(
sharerURL,
'facebook-share-dialog',
'width=626,height=436');
return false;
}
在彈出窗口中,“描述”文本看起來不錯。 但是當在facebook中看到時,描述不會顯示
共享時,可以看到說明(摘要文本) 。
但是說明(摘要文本)未顯示在Facebook中。
在您共享的任何頁面上,嘗試添加以下內容:
<meta property="fb:app_id" content="{Your_App_ID}"/>
<meta property="og:url" content="http://54.251.121.6/cnc/cupcakes-n-chai-side-table"/>
<meta property="og:title" content="Your title"/>
<meta property="og:image" content="http://imageURL"/>
<meta property="og:description" content="This is the description blah blah blah">
但是,如果您已經在使用JS,那么如何使用Facebook JS SDK?
只需將以下代碼放在標簽之后:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '{your-app-id}',
status : true,
xfbml : true
});
};
(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/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
然后,要調用共享對話框,只需調用以下命令:
FB.ui({
method: 'feed',
name: 'Your title',
link: 'http://54.251.121.6/cnc/cupcakes-n-chai-side-table',
picture: 'http://imageURL',
caption: '',
description: 'This is the description blah blah blah',
ref: '{your_reference_call_here}'
});
我的個人經驗表明,使用JS SDK共享內容比使用URL重定向方法更安全(確保沒有錯誤)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.