加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 放置FB.Event.subscribe的位置

发布时间:2020-12-13 17:07:44 所属栏目:PHP教程 来源:网络整理
导读:下面是我在我的网站上使用Facebook Like按钮(以及Share按钮)的代码. 它很棒.我点击了Like按钮,然后在我的Facebook帐户的个人资料页面上发布了一个很好的通知. Facebook甚至会自动生成一个恰好是我网站徽标的预览图像.精彩.我网站上的Like计数器总计正确. 所
下面是我在我的网站上使用Facebook Like按钮(以及Share按钮)的代码.

它很棒.我点击了Like按钮,然后在我的Facebook帐户的个人资料页面上发布了一个很好的通知. Facebook甚至会自动生成一个恰好是我网站徽标的预览图像.精彩.我网站上的Like计数器总计正确.

所以我想在Like按钮上记录点击次数.根据this页面,代码为FB.Event.subscribe(‘edge.create’,function(response){});允许你这样做.

我在下面的代码中应该放置代码FB.Event.subscribe(‘edge.create’,function(response){});

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">

    <?php

    echo '<div id="fb-root"></div>';

    echo "<script type='text/javascript'>
      window.fbAsyncInit = function() {
        FB.init({appId: 'my_fb_app_id',status: true,cookie: true,xfbml: true});
      };


      (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol +
          '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
      }());



    });

    </script>";


    echo '<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="" send="true" layout="button_count" width="450" show_faces="false" font="arial"></fb:like>'; 

?>

解决方法

我不完全确定这是否正确,但根据 this stack overflow thread,您将事件订阅代码放在FB.init()之后和匿名函数调用之前,

window.fbAsyncInit = function() {
    FB.init({
        appId  : 'sensored-app-id',status : true,// check login status
        cookie : true,// enable cookies to allow the server to access the session
        xfbml  : true  // parse XFBML
    });

    /* All the events registered */
    FB.Event.subscribe('comments.add',function (response) {
        // do something with response
        alert("comment added");
    });
};

(function() {
    var e = document.createElement('script');
    e.src = document.location.protocol + '//connect.facebook.net/fi_FI/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
}());

此外,如果您看到this developer’s code example,您会看到他也将事件订阅代码放在Facebook初始化代码之后.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读