捕捉事件,如果用户已经喜欢任何Facebook页面

如果用户已经喜欢你的页面但是它不工作,我正在使用以下代码来捕获事件。 它总是去那个用户不喜欢你的页面。

window.fbAsyncInit = function(){FB.init({appId:'app_id',// App ID channelURL:'path',//频道文件URL状态:true,//检查登录状态cookie:true,//启用cookie允许服务器访问会话oauth:true,//启用OAuth 2.0 xfbml:true //解析XFBML});

                FB.getLoginStatus(function(response) {
                    console.log(response);
                    if (response.authResponse) {
                        // logged in and connected user, someone you know
                        var user_id = response.authResponse.userID;
                        var page_id = "1457622007810260";
                        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);
                        alert(fql_query);
                        alert(user_id);
                        the_query.wait(function(rows) {
                            alert(rows);
                            if (rows.length == 1 && rows[0].uid == user_id) {
                                //user likes the page
                                //do your stuff here
                                alert('likes');
                            } else {
                                // user doesn't like our page yet
                                alert('unlikes');
                            }
                        });
                    } else {
                        // no user session available, someone not known, not logged into fb'
                        alert('no');
                    }
                });
            };

            // 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));

并在html中的某个地方


用户需要授予user_like的许可。 这需要您的申请被提交至Facebook.com并进行审核

https://developers.facebook.com/docs/facebook-login/permissions/v2.0

如果你想获得一个页面的所有粉丝,你将需要我认为的page_management许可。

Facebook展示了如何在程序上做到这一点:

https://developers.facebook.com/docs/facebook-login/login-flow-for-web/v2.0

链接地址: http://www.djcxy.com/p/35811.html

上一篇: Catch event if user have already liked any facebook page

下一篇: capture click of Facebook 'Like' button with jQuery