简体   繁体   English

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

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

I simply want to post an image and comment from my own site to the facebook users own wall. 我只想将图像和评论从我自己的站点发布到Facebook用户自己的墙。

I've looked in various places and through the Facebook API documentation but cant find a straight forward way of achieving what should be a rudimentary task. 我在各个地方和Facebook API文档中进行了浏览,但是找不到实现基本任务的直接方法。

FB's own documentation seems overly complex. FB自己的文档似乎过于复杂。 I have set up the app, along with objects and actions and aggregations from within the graph API tab but can't seem to get what I'm after. 我已经在图形API选项卡中设置了应用程序以及对象,动作和聚合,但是似乎无法获得所需的信息。

Can anyone suggest a method or article outlining the correct procedure that allows me to pass comment and image parameters, or an article that better deconstructs the problem than FB's own docs. 任何人都可以提出一种方法或文章来概述允许我传递注释和图像参数的正确过程,或者可以提供比FB自己的文档更好地解构该问题的文章。

Any pointers would be greatly appreciated. 任何指针将不胜感激。

Make an app in the developer.facebook.com backend and fill in your APP ID where appropriate below. 在developer.facebook.com后端制作一个应用,并在下面的相应位置填写您的APP 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM