2014-06-06 47 views
0

我正在使用以下代碼捕獲事件,如果用戶已經喜歡你的頁面,但它不工作。它總是去那個用戶不喜歡你的頁面。捕獲事件,如果用戶已經喜歡任何Facebook頁面

window.fbAsyncInit =函數(){ FB.init({ APPID: 'APP_ID',//應用ID channelURL: '路徑',//頻道文件URL 狀態:真,//檢查登錄狀態 cookie:true,//啓用cookie以允許服務器訪問會話 oauth:true,//啓用OAuth 2.0 xfbml:true //解析XFBML });

   FB.getLoginStatus(function(response) { 
        console.log(response); 
        if (response.authResponse) { 
         // logged in and connected user, someone you know 
         var user_id = response.authResponse.userID; 
         var page_id = "1457622007810260"; 
         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); 
         alert(fql_query); 
         alert(user_id); 
         the_query.wait(function(rows) { 
          alert(rows); 
          if (rows.length == 1 && rows[0].uid == user_id) { 
           //user likes the page 
           //do your stuff here 
           alert('likes'); 
          } else { 
           // user doesn't like our page yet 
           alert('unlikes'); 
          } 
         }); 
        } else { 
         // no user session available, someone not known, not logged into fb' 
         alert('no'); 
        } 
       }); 
      }; 

      // Load the SDK Asynchronously 
      (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)); 

和HTML

回答

1

用戶某處需要授予user_like permisison。這需要你的應用程序提交和審查是Facebook.com

https://developers.facebook.com/docs/facebook-login/permissions/v2.0 

如果你想獲得一個網頁上的所有球迷,你將需要page_management允許我看。

Facebook的展示瞭如何做到這一點programmacally上:

https://developers.facebook.com/docs/facebook-login/login-flow-for-web/v2.0

+0

但是,Facebook的做回一些頁面的id我想這是大小20的陣列但對於其他網頁?我最近喜歡? –

相關問題