[英]FB.API Facebook Open Graph returns empty data for user likes for some users
我有一个页面,当用户允许该应用程序时,它将列出该用户的喜欢页面,并检查该用户是否喜欢我的某个Facebook页面,并且是该Facebook页面的成员(两者相似) ,使用FB.API
问题是某些用户根本不返回任何数据,而与操作系统或浏览器无关。 我已经在应用程序上设置了“ user_likes”权限,但无济于事。
<html>
<head>
<title>My Facebook Login Page</title>
</head>
<body>
<div id="fb-root"></div>
<div id="lblName"></div>
<div id="lblAccessToken" style="display: none;"></div>
<br><br>
<fieldset>
<legend>Your Page Likes</legend>
<div id="lblLikes"></div>
</fieldset>
<fieldset>
<legend>Check whether you like [My Fan Page] </legend>
<div id="lblYouLike"></div>
</fieldset>
<fieldset>
<legend>Check whether you are a fan of [My Fan Page]</legend>
<div id="lblMem"></div>
</fieldset>
<div id="divLogin" style="display:none;">
<div class="fb-login-button">Login with [App]</div>
</div>
<script>
var accessToken;
var uid;
var lblName = document.getElementById("lblName")
var divLogin = document.getElementById("divLogin")
var lblAccessToken = document.getElementById("lblAccessToken")
var lblLikes = document.getElementById("lblLikes")
var lblYouLike = document.getElementById("lblYouLike")
var lblMem = document.getElementById("lblMem")
window.fbAsyncInit = function () {
FB.init({
appId: 'APP_ID', // App ID
channelUrl : 'http://www.example.com/testing/channel.html', // Channel File
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
FB.getLoginStatus(
function (response) {
checkStatus(response)
}
);
FB.Event.subscribe(
'auth.authResponseChange',
function (response) {
checkStatus(response)
}
);
FB.Event.subscribe(
'edge.create',
function (response) {
//alert('You liked the URL: ' + response);
ufCheckLike()
}
);
};
// 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 checkStatus(response){
if (response.status === 'connected') {
uid = response.authResponse.userID;
accessToken = response.authResponse.accessToken;
lblAccessToken.innerHTML = accessToken;
FB.api(
'/me',
'get',
function(response) {
lblName.innerHTML = response.name;
}
);
divLogin.style.display = "none";
ufCheckLike()
}
else {
divLogin.style.display = "";
}
}
function ufCheckLike() {
if (isLoggedIn()) {
FB.api(
'/me/likes?' +
'access_token=' + accessToken,
'get',
function(likes) {
if (likes) {
if (likes.data && likes.data.length > 0) {
for (var i = 0; i < likes.data.length; i++) {
var like_detail = likes.data[i]
var lsHTML = like_detail.name + " : " + like_detail.id + "<br>"
if(like_detail.id == "<PAGE_ID>")
lblLikes.innerHTML = lsHTML + lblLikes.innerHTML
else
lblLikes.innerHTML += lsHTML
}
}
}
}
);
FB.api(
'/me/likes/<PAGE_ID>?' +
'access_token=' + accessToken,
'get',
function(likes) {
if (likes) {
if (likes.data && likes.data.length > 0) {
lblYouLike.innerHTML = "You Like [Fan Page]!"
}
}
}
);
FB.api(
'/<PAGE_ID>/members/' + uid + '?' +
'access_token=' + accessToken,
'get',
function(likes) {
if (likes) {
if (likes.data && likes.data.length > 0) {
lblMem.innerHTML = "You are a fan of [Fan Page]!"
}
}
}
);
}
}
function isLoggedIn() {
if (!accessToken) {
divLogin.style.display = "";
return false;
}
return true;
}
</script>
</body>
</html>
我还实现了FQL,实际上它执行相同的操作来检查用户是否喜欢我的页面,并且在某些对象(数据对象返回空行)上发生了相同的情况。
var query = "SELECT uid FROM page_fan where uid=me() and page_id = PAGE_ID ' + 'and access_token = " + accessToken;
//Access token is optional
var names = FB.Data.query(query);
names.wait(
function (rows) {
if (rows.length > 0) {
// liked, do codes here
}
else {
// not yet liked, show like button
}
}
);
我已经应用了此处找到的一些建议,该脚本对于某些用户仍然不起作用。 除了在应用程序的用户和朋友权限设置中设置“ user_likes”外,我不知道应该修改哪些特定的帐户/隐私/应用程序设置以允许查询用户的页面赞。
您没有迹象表明这种情况发生的频率,所以我假设
如果是这样,则某些用户实际上没有任何喜欢,因此这很容易发生并且不应该成为问题。
如果您可以验证用户确实喜欢,并且已使用user_likes权限授权您的应用,请在Facebook的错误跟踪器中提交错误,并包括用户ID,页面ID,访问令牌等
这可能与该可复制错误有关: http : //developers.facebook.com/bugs/106991419491608在此处阅读我的文章以获取更多信息。
我在这篇文章中针对与JS api相似的问题发布了详细的解决方案: 为什么Facebook API会为相册返回一个空数组?
if(jQuery.type(response.data[i].location) == 'object' )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.