facebook like

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta property="fb:app_id" content="270946730017302" />
</head>
<body>
<h3>
    <div
            class="fb-like"
            data-share="true"
            data-width="450"
            data-show-faces="true" data-notify="true">
    </div>
    <div class="fb-follow" data-href="https://www.facebook.com/sherrydresses" data-layout="standard" data-size="small" data-show-faces="true" data-notify="true"></div>
</h3>
<script>
    window.fbAsyncInit = function() {
        FB.init({
            appId      : '270946730017302',
            xfbml      : true,
            version    : 'v2.9',
            status: false,
            cookie  : true,
            oauth: true
        });
        // In your JavaScript
        var auth_response_change_callback = function(response) {
            console.log("auth_response_change_callback");
            console.log(response);
//            alert(response);
        }

        var auth_status_change_callback = function(response) {
            console.log("auth_status_change_callback: " + response);
        }
        var edge_create = function(response,object) {
            console.log("edge_create: " + response+object.className);
        }
//        FB.Event.subscribe('auth.authResponseChange', auth_response_change_callback);
//        FB.Event.subscribe('auth.statusChange', auth_status_change_callback);

        FB.getLoginStatus(function(response) {
            if (response.status === 'connected') {
                // the user is logged in and has authenticated your
                // app, and response.authResponse supplies
                // the user's ID, a valid access token, a signed
                // request, and the time the access token
                // and signed request each expire
                var uid = response.authResponse.userID;
                var accessToken = response.authResponse.accessToken;
//                alert(uid);
                console.log(uid);

            } else if (response.status === 'not_authorized') {
                // the user is logged in to Facebook,
                // but has not authenticated your app
//                alert('the user is logged in to Facebook, ');
                console.log('the user is logged in to Facebook, ');


            } else {
                // the user isn't logged in to Facebook.
//                alert('the user isnt logged in to Facebook. ');
                console.log('the user isnt logged in to Facebook. ');



            }
        },true);
        FB.Event.subscribe('auth.authResponseChange', auth_response_change_callback);
        FB.Event.subscribe('auth.statusChange', auth_status_change_callback);
        FB.Event.subscribe('edge.create', edge_create);
        FB.Event.subscribe('edge.remove', edge_create);


        FB.AppEvents.logPageView();
    };

    (function(d, s, id){
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) {return;}
        js = d.createElement(s); js.id = id;
        js.src = "//connect.facebook.net/en_US/sdk.js";
//        js.src = "//connect.facebook.net/en_US/sdk/debug.js";
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
</script>
</body>
</html>

https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/v2.9
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Facebook提供了JavaScript SDK(Software Development Kit)来帮助开发者在其网站或应用中集成社交功能,包括发送通知、评论和分享。标准事件代码主要是用来跟踪用户的交互,例如点击、点赞、评论等,这对于分析用户行为和优化用户体验非常重要。 **Facebook标准事件代码安装教程**: 1. **包含Facebook SDK**: 首先,你需要在你的项目中引入Facebook的JS库,通常通过CDN链接或者下载到本地服务器。例如,你可以使用以下代码在HTML中引入: ```html <script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v13.0"></script> ``` 2. **初始化Facebook SDK**: 在页面加载完成后,你需要初始化SDK,通常会用到`FB.init()`函数,提供你的App ID以及一些配置选项: ```javascript window.fbAsyncInit = function() { FB.init({ appId: 'your_app_id', // 替换为你的Facebook App ID cookie: true, // 是否使用Cookie存储访问权限 xfbml: true, // 是否启用XFBML标记 version: 'v13.0' // SDK版本 }); }; (function(d, s, id) { var js, fjs = d.getElementsByTagName(s); if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = 'https://connect.facebook.net/en_US/sdk.js'; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); ``` 3. **触发事件并发送数据**: 当用户执行特定操作时,比如点击按钮,你可以创建一个函数来触发Facebook事件,例如`FB.Event.subscribe('edge.create')`。这会记录用户点赞的行为: ```javascript function trackLikeEvent() { FB.Event.subscribe('edge.create', function(response) { FB.api('/me/likes', 'get', { source: 'your_event_trigger' }, function(response) { // 在这里处理响应数据并发送到服务器 }); }); } // 在按钮点击或其他触发点调用此函数 document.getElementById('like-button').addEventListener('click', trackLikeEvent); ``` 4. **发送事件到Facebook Insights**: 为了让Facebook分析工具能够收集这些事件,你需要确保你在服务器端设置好了事件追踪,并且在`trackLikeEvent`中的`FB.api`调用后发送数据到服务器。 **相关问题--:** 1. 如何在不使用Facebook的JS SDK时手动发送事件? 2. Facebook Events API有哪些常用的事件类型? 3. 如何处理用户的隐私设置影响事件追踪?

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值