本文介绍了如何检查 facebook 粉丝专页是否被喜欢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您如何检查访问者是否喜欢 facebook 粉丝专页.所以我在代码中填写了我的app_id、page_id
How do you check wether a facebook fanpage has been liked by the visitor. So I fill in my app_id, page_id in the code
这是我现在得到的代码
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : 'APP_ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
channelUrl : 'http://domain.com/tab/', // channel.html file
oauth : false // enable OAuth 2.0
});
(function($) {
var session = FB.getSession();
FB.api({
method: 'fql.query',
query: 'SELECT uid, page_id FROM page_fan WHERE uid=me() AND page_id=PAGE_ID'
},
function(response) {
if(response instanceof Array && response.length > 0)
alert("YOU LIKE US!");
else
alert("YOU DON'T LIKE US YET!");
});
})(jQuery);
</script>
之后我收到此错误:
TypeError: FB.getSession is not a function
推荐答案
如果当前用户已经喜欢你的页面,你可以这样处理:
If the current user has already liked your page or not, you can handle like this:
FB.api("me/likes/PAGE_ID", function(response) {
if ( response.data.length == 1 ) { //there should be a single value inside `data` which is your page details
alert('you like us :-)')
} else {
alert('please like our page')
}});
这篇关于如何检查 facebook 粉丝专页是否被喜欢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!