【问题标题】:Update database field on Facebook "Like"更新 Facebook 上的数据库字段“Like”
【发布时间】:2011-07-26 09:55:46
【问题描述】:

我想跟踪人们何时点击我网站上的 Facebook“赞”按钮。

我有一个小脚本设置,但它似乎不起作用,我不知道它可能是什么。有什么建议么? AppID 是正确的,此脚本仅用于测试,所以不要介意缺少验证:

index.html

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
  <head>
    <title>FB Like Test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
      <div id="fb-root"></div>

<script type="text/javascript">

$(document).ready(function() {  

window.fbAsyncInit = function() {
    FB.init({appId: 'x', status: true, cookie: true, xfbml: true});
    FB.Event.subscribe('edge.create', function(href, widget) {
        $.ajax({
            type: 'POST',
            url: 'like-sql.php',
            data: ({liked : 1})
        });
    });

    FB.Event.subscribe('edge.remove', function(response) {
        $.ajax({
            type: 'POST',
            url: 'like-sql.php',
            data: ({liked : 0})
        });
    });

};
(function() {
     var e = document.createElement('script');
     e.type = 'text/javascript';
     e.src = 'http://connect.facebook.net/nl_NL/all.js#appId=x&amp;xfbml=1';
     e.async = true;
     document.getElementById('fb-root').appendChild(e);
}());
});  
</script>

 <fb:like href="http://x.x.x" layout="button_count" show_faces="true"  width="500"></fb:like>

  </body>
</html>

like-sql.php

<?php    
$status = $_POST['liked'];    
mysql_query("UPDATE `fb_like` SET umk_like = $status WHERE user_id = '3432'");    
?>

我是整个 jQuery ajax 的新手,所以我真的不知道应该如何调试它。欢迎任何建议:)

编辑:没关系,伙计们,我明白了。

我正在一个外部文件中对此进行测试,默认情况下我没有包含 jQuery ;) 我不敢相信我花了这么长时间才弄明白,哈哈。无论如何感谢所有的帮助!

【问题讨论】:

  • @sascha: 是的,我已经用总代码更新了 index.html
  • @gowri:这实际上是一个不同的问题,我希望它被注意到。
  • 尝试在你的ajax调用中加入success:function(data)和error:function(jqXHR, textStatus, errorThrown) 然后你可以提醒这些变量,看看发生了什么
  • @tommy:我尝试了以下操作:success : function(data) { alert(data); }, error : function(jqXHR, textStatus, errorThrown) { alert(data); },但没有任何警报。甚至在提醒某些文本时也不会。

标签: php jquery facebook


【解决方案1】:

尝试在事件侦听器本身中提醒()某些东西,看看它是否被正确订阅

FB.Event.subscribe('edge.create', function(href, widget) {
    alert('Like caught !');
    $.ajax({
        type: 'POST',
        url: 'like-sql.php',
        data: ({liked : 1})
    });
});

并将 notify=true 添加到 fb:like

<fb:like notify="true" href="http://x.x.x" layout="button_count" show_faces="true"  width="500"></fb:like>

我在“comment.create”中遇到了同样的问题,我通过 notify="true" 解决了这个问题,并订阅了“cmets.add”!但我仍然无法订阅“comment.remove”!

【讨论】:

  • 我确实收到了警报,但 notify=true 并没有帮助我:(
  • 我可以从 like-sql.php 文件中触发一些东西,以检查它是否正确运行该文件?
  • 那太好了..我有一个问题,因为“赞”按钮对我不起作用。我在 localhost 上运行,你也在 localhost 上运行吗?
  • 是的,可能是 FB AppId 设置?我已将我的 AppID 的域和 URL 设置为 localhost。
  • 是的,我已将它们设置为 localhost,它适用于身份验证和 cmets,但不适用于喜欢! :(
【解决方案2】:

没关系,伙计们,我明白了。

我正在一个外部文件中对此进行测试,默认情况下我没有包含 jQuery ;) 我不敢相信我花了这么长时间才弄明白,哈哈。感谢所有的帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-16
    • 2012-09-07
    • 2010-11-30
    • 2013-03-27
    • 1970-01-01
    相关资源
    最近更新 更多