当我检查是否有人喜欢我的页面时遇到了问题。我可以让大多数用户喜欢信息,但是使用api /me/likes/pageID
,少数用户只返回类似"FB.__globalCallbacks.f2508bd33b46a1e({"data":[]});"
的响应,数据为空。我在"https://developers.facebook.com/tools/explorer?method=GET&path=me%2Flikes"
中调试了accessToken,它只返回相同的结果。
这是我的JavaScript代码。谁能告诉我我做错了什么?
//use jquery init FB
$.ajaxSetup({ cache: true });
$.getScript('//connect.facebook.net/zh_HK/all.js', function(){
// alert('初始化FACEBOOK,APPID是'+appId);
FB.init({
appId : appId, // App ID from the app dashboard
status : true, // Check Facebook Login status
xfbml : true, // Look for social plugins on the page
cookie : true,
frictionlessRequests:true
});
var redirectURL=encodeURIComponent('https://apps.facebook.com/myapp?scope=offline_access,user_likes,email');
// Additional initialization code such as adding Event Listeners goes here
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a~-0 valid access token, a signed
// request, and the time the access token
// and signed request each expire
fbId = response.authResponse.userID;
accessToken = response.authResponse.accessToken;
} else if (response.status === 'not_authorized') {
window.top.location.href = 'https://www.facebook.com/dialog/oauth?client_id=' + appId + '&redirect_uri='+redirectURL;
} else {
window.top.location.href = 'https://www.facebook.com/dialog/oauth?client_id=' + appId + '&redirect_uri=' +redirectURL
}
});
FB.Event.subscribe('edge.create',
function(response) {
hideLayer('fb_like_box');
});
});
//check fan or not
FB.api('/me/likes/'+PageId, function (result) {
if (result.data[0]) {
alert('fan!')
} else {
alert('not fan!')
);
return;
}
});