多个Facebook共享按钮在同一页面上

时间:2015-12-02 22:55:52

标签: javascript facebook api share

我有一个包含许多图片的网页。每张图片上都有一个Facebook分享按钮和一些描述。我想要做的是,当用户点击分享按钮时,相应的图像和该特定图像的描述将在Facebook上共享。

我一直关注Facebook的文档,到目前为止我所理解的是Facebook获取了您想要共享的页面的链接,并从中选择了一个图像,该图像显示在共享帖子上。

有没有办法可以在共享帖子中指定图片的网址和说明文字?

1 个答案:

答案 0 :(得分:0)

在共享网址中,您可以指定要共享的图像的div,并为每个共享按钮创建一个EventListener。

//add event listener to the first share button
document.getElementById('share_btn1').addEventListener('click', function() {
    FB.ui({
        method: 'share_open_graph',
        action_type: 'og.likes',
        action_properties: JSON.stringify({
            object:'http://yourdomain.com/share.php#div_img1',
        })
    }, 
    function(response){
      // Debug response (optional)
      console.log(response);
    });

}, false);


//add event listener to the second share button
document.getElementById('share_btn2').addEventListener('click', function() {
    FB.ui({
        method: 'share_open_graph',
        action_type: 'og.likes',
        action_properties: JSON.stringify({
            object:'http://yourdomain.com/share.php#div_img2',
        })
    }, 
    function(response){
      // Debug response (optional)
      console.log(response);
    });

}, false); 
相关问题