Facebook分享按钮功能

时间:2013-05-01 07:43:53

标签: facebook facebook-like

我想在我的网站上添加Facebook分享按钮,以便用户可以分享任何帖子,给定网址的内容。 我想知道如何让用户在Facebook上共享或不共享,因为如果用户从我的网站分享任何帖子,给定网址的内容,我必须将用户数据存储在数据库中。

<a href="https://www.facebook.com/sharer/sharer.php?u=example.org" target="_blank">
  Share on Facebook
</a>

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。

代码: -

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
<title>My Feed Dialog Page</title>
<script src="http://code.jquery.com/jquery-latest.pack.js" type="text/javascript"></script>
</head>
<body>
<div id='fb-root'></div>
<script src='http://connect.facebook.net/en_US/all.js'></script> 
<a onclick='postToFeed(); return false;' style="cursor:pointer;"><img src="img/xyz.jpg"></a>
<p id='msg' style="display:none"><?php echo $_REQUEST['id'] ?></p>
<script> 

       FB.init({appId: "your app id", status: true, cookie: true});
        function postToFeed() { 
             var obj = {
                      method: 'feed',
                      //redirect_uri: 'YOUR URL HERE',
                      link: 'https://www.abc.in/',
                      picture: 'http://fbrell.com/f8.jpg',
                      name: 'abc',
                      caption: 'User Has Won points ',
                      description: 'Share Test.'
                    };
         function callback(response) {  
               //document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
               var id=$("p").html();
              if(response['post_id']!=null)
              {
                $.ajax({
                    url:'customer.php',
                    data:'fbpoints='+'1'+'&customer_id='+id,
                    dataType:'html',
                    success:function(res){ alert(res);
                     } 
                 });

             }

        }
        FB.ui(obj, callback);
      }
    </script>
</body>
</html>