使用Facebook API将图像和评论发布到用户墙的简单方法


Simple way to post image and comment to users wall with Facebook API

我只是想从我自己的网站发布一张图片和评论到Facebook用户自己的墙上。

我查看了不同的地方并浏览了Facebook API文档,但找不到一种直接的方法来实现本应是一项基本任务。

FB自己的文档似乎过于复杂。我已经设置了该应用程序,以及图形 API 选项卡中的对象、操作和聚合,但似乎无法获得我想要的东西。

任何人都可以建议一种方法或文章概述允许我传递评论和图像参数的正确程序,或者一篇比FB自己的文档更好地解构问题的文章。

任何指示将不胜感激。

在 developer.facebook.com 后端创建一个应用,并在下面适当的地方填写你的应用 ID。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">  
    <title>Facebook Sharer</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>

    <script>
    $(function() 
    {
        $('#share_button').live('click', function(e)
        {
            e.preventDefault();
            var share_name          = $('input[name="share_name"]').val();
            var share_link          = $('input[name="share_link"]').val();
            var share_image         = $('input[name="share_image"]').val();
            var share_caption       = $('input[name="share_caption"]').val();
            var share_description   = $('input[name="share_description"]').val();
            var share_redirect      = $('input[name="share_redirect"]').val();

            FB.ui(
            {
                method:         'feed',
                name:           share_name,
                link:           share_link,
                picture:        share_image,
                caption:        share_caption,
                description:    share_description
                //message:      ''
            },
            function(response) 
            {
                if (response && response.post_id) 
                {
                    //alert('thanks for sharing!');
                    window.top.location.href = share_redirect;
                } 
                else 
                {
                    //alert('Post was not published.');
                }
            });
            // return false;
        });

    });
    </script>

</head>
<body>

<div id="share_button">share me!</div>

<input type="text" name="share_name" value="Boffins" />
<input type="text" name="share_link" value="http://google.com"/>
<input type="text" name="share_image" value="http://sstatic.net/stackoverflow/img/tag-logo-facebook.png"/>
<input type="text" name="share_caption" value="Yes"/>
<input type="text" name="share_description" value="sadfdsdsfasdaffdasfds"/>
<input type="text" name="share_redirect" value=""/>

<div id="fb-root"></div>


<script type="text/javascript">

window.fbAsyncInit = function()
{
    FB.init({
        appId   : [APP ID],
        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>


</body>
</html>