[英]How to check whether user already likes a page or not using FB.api?
我使用下面的代码来检查用户是否已经喜欢该页面。
window.fbAsyncInit = function () {
FB.init({
appId: 'XXXXXXXXXXX', // App ID
channelUrl: '//' + window.location.hostname + '/channel', // Channel File
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
oauth: true,
xfbml: true // parse XFBML
});
FB.getLoginStatus(function (response) {
if (response && response.authResponse) {
getAPIResponse();
}
else {
FB.login(function (response) {
if (response.authResponse) {
getAPIResponse();
}
else {
document.getElementById('MainView').style.display = 'none';
}
});
}
});
};
// Load the SDK asynchronously
(function (d) {
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) { return; }
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
} (document));
function getAPIResponse() {
FB.api("me/likes/XXXXXXXXXXXXX", function (response) {
if (response.data.length == 1) {
document.getElementById('MainView').style.display = 'block';
} else {
document.getElementById('MainView').style.display = 'none';
alert("Like our Page to show Calendar");
}
});
}
上面的代码以前可以正常工作。 但是现在response.data.length始终返回零。 如何解决上述问题?
似乎您没有在请求使用like信息所必需的user_likes
权限。
看到
此外,从您的代码示例中,您似乎“喜欢”内容,这是Facebook所不允许的,因此可能不允许您通过“登录评论”,这对于使用user_likes
是必需的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.