开发者

Displaying like / unlike pages in facebook

I have been trying to make facebook page that will display different content depending on the Like / Unlike. I found the code below on this site which works to a certain extent however not in Chrome Browser - I also get a nasty pop-up that is XD Proxy. In firefox this pops up and then goes away before working perfectly. Any help would be greatly appreciated.

Index.html (displayed in the 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百科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 is:

$(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
      }
    });

});

Many thanks in advance to anyone that can help. And thanks to the previous poster that has got me this far.


Your fql query needs a space after the page_id. It should read:

var fql_query = "SELECT uid FROM page_fan WHERE page_id = "+page_id+" and uid="+user_id;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜