使用app id将图像发布到Facebook应用中

时间:2014-03-14 04:21:27

标签: javascript facebook facebook-apps

我需要在我的Facebook应用中使用图片网址发布图片是可能的吗?  如何在按钮点击时将图像发布到Facebook?  我已将imageUrl存储在变量图像中,将facebook URL存储在变量shareUrl中,

following is the complete facebook URL : 
"https://www.facebook.com/dialog/feed?app_id=843228839026054&caption=example.com&display=popup&redirect_uri="+encodeURIComponent("http://www.facebook.com/")+"&name=%title%&description=%desc%&picture=%image%".

<html>
<head>
<script>

var doShare = function(title, description)
{
    if(title && description)
    {
        image="http://www.sxc.hu/assets/182945/1829445627/small-flowers-1019552-m.jpg";

        /* for readability i store the url like this, above this code u can find
          the complete facebook url. */

        shareUrl = "https://www.facebook.com/dialog/feed?";
        shareUrl += "app_id=843228839026054&caption=example.com&display=popup&";
        shareUrl += "redirect_uri="+encodeURIComponent("http://www.facebook.com/");
        shareUrl += "&name=%title%&description=%desc%&picture=%image%";

        var url = shareUrl.replace(/%title%/g, encodeURIComponent(title));
        url = url.replace(/%desc%/g, encodeURIComponent(description));
        url = url.replace(/%image%/g, encodeURIComponent(image));
        var isOpen = window.open(url);
        if(!isOpen)
        {
          console.log('Please turn off "Block pop up" setting to proceed further.');
        }
    }
};

</script>
</head>
<body>
<div id='share'>
    <input type='button' onclick ='doShare("TITLE","DESCRIPTION")'>Share</input>
</div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

FB.ui({
                                method: 'feed',
                                name: "some name",
                                link: "somelink.com",
                                picture: urltobeshared,
                                caption: 'some caption',
                                description: "some descrtiption",
                              },
                              function(response) {
                                if (response && response.post_id) {
                                  console.log('Thank you');
                                }                  
                              }
                        );
                    },

docs here。希望有所帮助