2012-11-15 132 views
0

如何檢查訪客是否喜歡Facebook粉絲頁面。所以我填我的APP_ID,PAGE_ID代碼如何檢查Facebook粉絲頁面是否受到歡迎

這是我必須得

<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 

回答

0

的FB.getSession方法已被棄用。改爲使用FB.getAuthResponse

2

如果當前用戶已經喜歡你的網頁或沒有,你可以處理這樣的:

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') 
 }}); 
+1

你將需要爲這個user_likes –

相關問題