我一直在努力制作Facebook页面,根据Like / Different显示不同的内容。我发现这个网站上面的代码在某种程度上起作用,但不在Chrome浏览器中 - 我也得到一个令人讨厌的弹出窗口,即XD代理。在Firefox中,弹出然后在完美工作之前消失。 任何帮助将不胜感激。
Index.html(显示在iFrame中)
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8' />
<title>BASE</title>
<link rel='stylesheet' href='css/style.css' />
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'></script>
<script src='js/example.js'></script>
</head>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : '114317821995273',
status : true,
cookie : true,
xfbml : true
});
</script>
<div id="container_notlike">
YOU DONT LIKE
</div>
<div id="container_like">
YOU LIKE
</div>
</body>
</html>
Javascript是:
$(document).ready(function(){
FB.login(function(response) {
if (response.session) {
var user_id = response.session.uid;
var page_id = "187015391355550"; //Test Page
var fql_query = "SELECT uid FROM page_fan WHERE page_id = "+page_id+"and uid="+user_id;
var the_query = FB.Data.query(fql_query);
the_query.wait(function(rows) {
if (rows.length == 1 && rows[0].uid == user_id) {
$("#container_like").show();
//here you could also do some ajax and get the content for a "liker" instead of simply showing a hidden div in the page.
} else {
$("#container_notlike").show();
//and here you could get the content for a non liker in ajax...
}
});
} else {
// user is not logged in
}
});
});
非常感谢能够提供帮助的任何人。感谢上一张让我走到这一步的海报。
答案 0 :(得分:1)
你的fql查询在page_id之后需要一个空格。 它应该是:
var fql_query = "SELECT uid FROM page_fan WHERE page_id = "+page_id+" and uid="+user_id;