当用户分享到facebook的链接时更新数据库


update database when a user shared a link to facebook

是否有可能更新数据库,一旦用户在我的网站共享一个链接?

例如,如果他们分享链接,他们的帐户将获得一些积分。

我怎样才能确保他们真的分享到facebook的链接,而不是只是点击分享然后关闭弹出窗口…

我不熟悉facebook,刚才试着谷歌了一下,但仍然没有找到答案…

谢谢。编辑:

   <script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" 
    type="text/javascript">
   </script>
   <a name="fb_share" type="button" share_url="script2.php?id=XXX"> 

更新(2013年8月21日): Facebook的api自最初发布以来发生了变化。跟踪点赞的方式还是一样的(阅读下面的原始答案),但是分享按钮的状态发生了变化。

弃用消息/info。在文档中的任何地方都不再可见,但在这个bug中可以看到。根据这个文档,共享按钮似乎仍然可用。但facebook并没有直接追踪份额的方法。我也不知道有任何黑客跟踪股票。


原始答:

From Facebook docs at this link.

"分享"按钮已经被"喜欢"按钮取代,并且将不再被支持。请尽可能使用"喜欢"按钮,为您的应用程序带来最大的流量。

那么我来告诉你如何为like按钮做这个:

首先使用Javascript sdk

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'YOUR_APP_ID', // App ID
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });
    // Additional initialization code here
    // you can subscribe to events here
    // edge.create event is fired only when the user likes (which means that the wall post has already happened, when the like button was clicked) 
    FB.Event.subscribe('edge.create',
   function(response) {
    alert('You liked the URL: ' + response);
            // you can do some ajax call to your backend and update your database
   }
); 
  };
  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     d.getElementsByTagName('head')[0].appendChild(js);
   }(document));
  </script>

在你的页面的某个地方包含点赞按钮

<fb:like href="http://example.com/fblike/" 
     send="true" width="450" show_faces="false"
     >
</fb:like>

您也可以更改在"喜欢"按钮中显示的单词,从"喜欢"到"推荐",您应该尝试从此链接自动生成您的"喜欢"按钮代码。

我猜你正在寻找这个http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/您需要订阅此事件

是可能的。

示例链接:

<a href="?share=YOUR+URL">SHARE TO FACEBOOK</a>

处理

示例代码
if(isset($_GET['share']))
{
    if(mysql_query("insert into table X() value()"))
    {
        //open window, you can use header('location:..') or meta redirect or another way, in this sample i'm using javascript window.open;
        echo '<script>window.open("http://www.facebook.com/sharer.php?u='.urlencode($_GET['share']).'","share","width=600,height=400");</script>';
    }
}

要实现facebook的"喜欢"按钮,这个链接也许可以帮助你

您不需要facebook,您可以在有人点击您页面上的Like按钮时执行Javascript AJAX调用。该调用将写入数据库。