FB喜欢按钮点击事件

时间:2013-11-08 01:54:30

标签: facebook

如何检测点击事件等FB OTHER页面? 我登录了一个页面,有其他id页面的按钮。

FB.init({
    appId       : '8888888888', // App ID
    channelUrl  : 'http://channel.com',
    status      : true, // check login status
    cookie      : true, // enable cookies to allow the server to access the session
    xfbml       : true, // parse XFBML
});
FB.login(function(response) {
    if (response.status == 'connected') {
        var other_page_id = "333333333333";  
        FB.api('/me/likes/'+other_page_id, function(response) {
            // check already liked other_page on start...
        });
    }
});
FB.Event.subscribe('edge.create', function(response) {
    //user just clicked "like" on MY page (id=8888888888), but I need other_page_id (id=333333333333) click event...
});

1 个答案:

答案 0 :(得分:0)

所以我理解,如果用户在FB.Event.subscribe

喜欢其他页面时喜欢某个页面,那么您想要
window.fbAsyncInit = function () {
        FB.init({
            appId: 'XxXxXxXxXxXxX', // App ID
            status: true, // check login status
        });

        FB.Event.subscribe('edge.create',

        function (response) {
            console.log('Checking if you liked Coca-Cola :)!');

            FB.getLoginStatus(function (response) {
                if (response.authResponse) {
                    // logged in and connected user with Your APP
                    var user_id = response.authResponse.userID; // Get the user Id from oAuth response and give it a variable 
                    var page_id = "178568815531741"; // Coca-Cola Page ID

                    // Use FQL to get the user likes
                    var fql_query = "SELECT uid FROM page_fan WHERE page_id = " + page_id + "and uid=" + user_id; 
                    var the_query = FB.Data.query(fql_query); 

                    the_query.wait(function (rows) {

                        if (rows.length == 1 && rows[0].uid == user_id) {
                            // If user has liked the Page 
                            console.log('You like Coca-Cola');
                        } else {
                            // If user has not liked the Page  
                            console.log('You don\'t like Coca-Cola');
                        }
                    });

                } else {
                    // If Use has not connected with Your APP, You can show the show the a Login button! 
                    console.log('Login to My App');
                }
            });
        })

};