2013-05-01 133 views
1

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

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

而不是'sharer.php'你为什么不使用'Dialog'使用,你可以做你需要轻松的工作饲料? – 2013-05-01 07:49:17

+0

@AnveshSaxena可以饲料对话框工作没有app_id或没有Facebook页面或应用程序? – Prince 2013-05-01 07:59:35

+0

它需要一个应用程序ID – 2013-05-01 08:20:08

回答

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>