1

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

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

1 回答 1

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>
于 2013-05-08T12:05:31.503 回答