我正在使用以下代码来捕获事件,如果用户已经喜欢您的页面但它不起作用。总是那个用户不喜欢你的页面。
window.fbAsyncInit = function(){ FB.init({ appId:' app_id',//应用ID channelURL:'路径',//频道文件网址 status: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中的某个地方
答案 0 :(得分:1)
用户需要授予user_like permisison。这要求您的申请提交给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