[英]FB share SDK not working - only displays stock app photo
我正在使用以下代码在FB上共享我的页面。 数据标题,数据描述和数据图像不共享。 当对话框链接弹出时,FB仅显示应用程序默认照片。 共享后,href正确共享,并显示应用程序默认照片。
代码在下面,并且我还在脚本的底部粘贴了我的头(带有og标签)。 那里有冲突吗? FB无法读取我的php标签吗?
任何帮助表示赞赏。
的HTML:
<li><div id="fb-root"></div>
<a class="fb_share" href="<?php echo JO_Request::getInstance()->getFullUrl(); ?>" data-image="" data-title="<?php echo $this->mypage['postTitle']; ?>" data-desc="<?php echo $this->mypage['postDesc'] ? nl2br(substr($this->mypage['postDesc'], 0, 200)) . '...' : ''; ?>" data-width="450"><img src="https://www.mygoodness.com/date/myimage.png" alt="" width="20" height="20"></a></li>
脚本:
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId: 'app id',
secret: 'app secret',
status: true,
cookie: true,
xfbml: true
});
};
(function(d, debug)
{var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/ false));
function postToFeed(title, desc, url, image) {
FB.XFBML.parse();
var obj = {method: 'feed',link: url, picture: image,name: title,description: desc};
function callback(response) {}
FB.ui(obj, callback);
}
var fbShareBtn = document.querySelector('.fb_share');
fbShareBtn.addEventListener('click', function(e) {
e.preventDefault();
var title = fbShareBtn.getAttribute('data-title'),
desc = fbShareBtn.getAttribute('data-desc'),
url = fbShareBtn.getAttribute('href'),
image = fbShareBtn.getAttribute('data-image');
postToFeed(title, desc, url, image);
return false;
});
</script>
头:
<head prefix="og:http://ogp.me/ns# fb:http://ogp.me/ns/fb#">
<!-- Meta -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=echo,chrome=1">
<meta property="fb:app_id" content="app id">
<meta property="og:url" content="<?php echo JO_Request::getInstance()->getFullUrl(); ?>">
<meta property="og:title" content="<?php echo $this->mypage['postTitle']; ?>">
<meta property="og:image" content="<?php echo $this->baseUrl;?>myhome.png">
<meta property="og:type" content="website">
<meta property="og:description" content="<?php echo $this->mypage['postDesc'] ? nl2br(substr($this->mypage['postDesc'], 0, 200)) . '...' : ''; ?>">
</head>
实际上,您的标记已正确实施,问题在于您设置要在对话框中显示以共享的图像执行在开放空间图中设置的限制。 (最大限制为8mb)
捷克文文档,介绍可以实现网络的开放图标记。
共享Open Graph网站管理员指南
您也可以使用此调试器检查链接以获取开放图,我认为您将非常有用。 共享调试器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.