如何使用Facebook应用程序与Post数据共享Pic?

时间:2014-07-16 08:30:13

标签: jquery facebook facebook-graph-api facebook-sharer

我正在使用以下代码来共享功能:

HTML CODE是:

<div id="fb-root">
</div>
<img src="share_button.png" id="share_button">

我的Jquery代码是:

<script>
window.fbAsyncInit = function () {
    FB.init({
        appId: '********',
        status: true, // check login status
        cookie: true, // enable cookies to allow the server to access the session
        xfbml: true // parse XFBML
    });
};

(function () {
    var e = document.createElement('script');
    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
} ());
</script>
<script type="text/javascript">
$(document).ready(function () {
    $('#share_button').live('click', function (e) {
        //var title = 'HyperArts Blog test test test';
        //var image = 'http://world.g-shock.com/us/en/ble/common/img/appIcon.png';
        //var Caption = 'test test test test';
        var description = 'my testing he HyperArts Blog provides tutorials for all things Facebook';
        //var link = 'http://hyperarts.com/blog';

        var image = $('[id$=imgAuthorAvatar]').attr("src");
        var title = $('[id$=lblTitle]').text();
        var Caption = 'Posted By ' + $('[id$=hlUserName]').text();
        var description = 'my testing he HyperArts Blog provides tutorials for all things Facebook';
        var link = document.URL;

        e.preventDefault();
        FB.ui(
                {
                    method: 'feed',
                    name: title,
                    link: link,
                    picture: image,
                    caption: Caption,
                    description: description,
                    message: ''
                });
    });
});

一切正常,但是当我分享到Facebook时,它并没有显示图像。

Here is the Post shared by me on Facebook

请帮助我如何在Facebook墙上显示帖子。我可以看到分享中的图片弹出。但在分享后,它在帖子中不可见。

请帮忙。

1 个答案:

答案 0 :(得分:0)

picture参数的图片网址必须是绝对的(http / https),并且必须是公开的。它没有显示的另一个原因可能是宽高比和大小,有关详细信息,请参阅此内容:https://developers.facebook.com/docs/opengraph/howtos/maximizing-distribution-media-content#images