如果用户已经喜欢您的页面但它不起作用,我正在使用以下代码来捕获事件。它总是指向该用户不喜欢您的页面。
window.fbAsyncInit = function() { FB.init({ appId : 'app_id',//应用程序 ID channelURL : 'path',// channel 文件 URL status : true,//检查登录状态 cookie : true,//启用cookie以允许服务器访问 session 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
关于javascript - 如果用户已经喜欢任何 Facebook 页面,则捕获事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24080948/