我尝试了旧的Facebook API方法,它已弃用,不再适用。现在我用/ me / likes / {page-id}来检索我的Facebook帐户是否喜欢这个页面。我需要检测用户是否喜欢所有粉丝页面,然后才采取具体行动。
FB.api("me/likes/184522495376661", function(response) {
if ( response.data.length === 1 ) {
FB.api("me/likes/1125511580839629", function(response) {
if ( response.data.length === 1 ) {
FB.api("me/likes/1603408753260758", function(response) {
if ( response.data.length === 1 ) {
// Specific action takes place here
} else {
alert("You haven't like third page!");
console.log(JSON.stringify(response));
}
});
} else {
alert("You haven't like second page!");
console.log(JSON.stringify(response));
}
});
} else {
alert("You haven't like our first page!");
console.log(JSON.stringify(response));
}
});
每个用户在检测到页面喜欢之前都需要Facebook登录。
FB.login(function (response) {
if (response.status === "connected") {
var uID = response.authResponse.userID;
fb_id = uID;
}else if (response.status === "not_authorized") {
}
},{ scope: 'email,user_likes,public_profile' });
以上代码适用于我个人的Facebook帐户。但是当涉及到其他facebook id时,me/likes/{page-id}
返回null,但该特定Facebook帐户已经像页面一样,API无法检测到。