Facebook 检测用户是否喜欢我的粉丝页面
编辑: 经过长时间的搜索,我终于找到了解决方案: 这是我的密码:Facebook 检测用户是否喜欢我的粉丝页面,facebook,facebook-like,detect,Facebook,Facebook Like,Detect,编辑: 经过长时间的搜索,我终于找到了解决方案: 这是我的密码: <html xmlns:fb="http://ogp.me/ns/fb#"> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script> </head> <
<html xmlns:fb="http://ogp.me/ns/fb#">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<fb:like href="http://developers.facebook.com" send="true" width="450" show_faces="true"></fb:like>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
<script>
FB.Event.subscribe('edge.create', function(href, widget) {
//alert('like '+href);
document.getElementById('download').style.visibility = 'visible';
});
FB.Event.subscribe('edge.remove', function(href, widget) {
//alert('dislike '+href);
document.getElementById('download').style.visibility = 'hidden';
});
</script>
<div id="download">Download</div>
</body>
</html>
即使我登录FB并使用相同的浏览器,它仍会返回以下错误(firebug调试日志)
代码:2500
消息:“必须使用活动访问令牌查询有关当前用户的信息。”
我对FB API了解不多,我做错什么了吗?以下是您的代码编辑,应该可以使用:
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXXXXX',
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
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 valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
FB.api('me', function(user) {
if (user) {
var image = document.getElementById('image');
image.src = 'http://graph.facebook.com/' + user.id + '/picture';
var name = document.getElementById('name');
name.innerHTML = user.name
}
});
} else {
// the user is logged in to Facebook,
// but has not authenticated your app or
// the user isn't logged in to Facebook.
FB.login(function(response) {
if (response.authResponse) {
FB.api('me', function(user) {
if (user) {
var image = document.getElementById('image');
image.src = 'http://graph.facebook.com/' + user.id + '/picture';
var name = document.getElementById('name');
name.innerHTML = user.name
}
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
});
}
});
};
(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));
为了解释一下,我添加了一个函数来检查用户是否已经授权了你的应用程序,在该函数的成功处理程序中,我添加了你的API调用。在这个函数的else中,我添加了一个调用,该调用将提示未经授权的用户对您的应用进行身份验证。如果他们成功地做到了这一点,您的API调用就会被调用,如果他们选择不这样做,我就在示例console.log调用中留下了,但是您可以用您想要的任何东西替换它
现在,为了跟踪用户是否喜欢您的页面,您需要通过跟踪“edge.create”事件来使用该功能 下面是您的代码编辑,应该可以使用:
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXXXXX',
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
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 valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
FB.api('me', function(user) {
if (user) {
var image = document.getElementById('image');
image.src = 'http://graph.facebook.com/' + user.id + '/picture';
var name = document.getElementById('name');
name.innerHTML = user.name
}
});
} else {
// the user is logged in to Facebook,
// but has not authenticated your app or
// the user isn't logged in to Facebook.
FB.login(function(response) {
if (response.authResponse) {
FB.api('me', function(user) {
if (user) {
var image = document.getElementById('image');
image.src = 'http://graph.facebook.com/' + user.id + '/picture';
var name = document.getElementById('name');
name.innerHTML = user.name
}
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
});
}
});
};
(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));
为了解释一下,我添加了一个函数来检查用户是否已经授权了你的应用程序,在该函数的成功处理程序中,我添加了你的API调用。在这个函数的else中,我添加了一个调用,该调用将提示未经授权的用户对您的应用进行身份验证。如果他们成功地做到了这一点,您的API调用就会被调用,如果他们选择不这样做,我就在示例console.log调用中留下了,但是您可以用您想要的任何东西替换它
现在,为了跟踪用户是否喜欢您的页面,您需要通过跟踪“edge.create”事件来使用该功能 我也在寻找同样的东西,如果有人能在这方面帮助我们会很好:)我也在寻找同样的东西,如果有人能在这方面帮助我们会很好:)我尝试了你的代码,但当它不起作用时,我编辑了我的代码,只需检查它‘你能比‘不起作用’更具体吗?—什么错误?另外,您正在用实际的应用程序ID替换XXXXXX位,对吗?是的,我正在插入实际的应用程序ID,当我调试时,它没有进入FB.getLoginStatus函数,因此无法跟踪准确的错误。我尝试了您的代码,但当它不工作时,我已经编辑了我的代码,只需检查它“您能比“不工作”更具体吗”-什么错误?另外,您正在用实际的应用程序ID替换XXXXXX位,对吗?是的,我正在插入实际的应用程序ID,当我调试时,它没有进入FB.getLoginStatus函数,因此无法跟踪准确的错误。