FB에서 내 페이지를 공유하려면 다음 코드를 사용하고 있습니다. data-title, data-desc 및 data-image는 공유하지 않습니다. 대화 상자 링크가 팝업되면 FB는 앱 기본 사진 만 표시합니다. 공유되면 href가 올바르게 공유되고 앱의 기본 사진이 표시됩니다.FB 공유 SDK가 작동하지 않음 - 재고 앱 사진 만 표시
코드가 아래에 있으며 스크립트의 맨 아래에 머리글 (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>
스크립트 코드는 내 본성이 필요합니다. fb –
@RuiCosta Thanks Rui. 당신은 - ian
예, 작동하지 않으면 콘솔 로그 오류 포착 후 –