2011-06-28 77 views
0

我需要獲取用戶的所有事件,但從現在開始。 我使用Facebook的API SDK V3.0從圖表api過濾事件facebook

這是我的代碼:

if ($user) { 
       try { 
        $events = $facebook->api("/me/events"); 
       } catch (FacebookApiException $e) { 
        echo ($e); 
       } 
      } 

回答

2

您可以運行類似FQL查詢是這樣的:

SELECT eid, name, start_time, end_time 
FROM event 
WHERE eid IN (SELECT eid 
       FROM event_member 
       WHERE uid = me()) 
and start_time > now() 

這將需要user_eventsextended permission

完整的示例:

<!DOCTYPE html> 
<html> 
<body> 
<div id="fb-root"></div> 
<a href="#" onclick="getEvents();return false;">Get Events</a> 
<script src="http://connect.facebook.net/en_US/all.js"></script> 
<script> 
    FB.init({ appId : 'yourAppId', status : true, cookie : true, xfbml : true }); 

    function getEvents() { 
    FB.login(function(response) { 
     if (response.session && response.perms) { 
     FB.api(
      { 
      method: 'fql.query', 
      query: 'SELECT eid, name, start_time, end_time FROM event WHERE eid IN (SELECT eid FROM event_member WHERE uid = me()) and start_time > now()' 
      }, 
      function(response) { 
      alert('Events: ' + JSON.stringify(response)); 
      } 
     ); 
     } 
    } , {perms:'user_events'}); 
} 
</script> 
</body> 
</html> 
+0

謝謝! 我閱讀這個文檔http://developers.facebook.com/docs/reference/fql/event/,我嘗試使用SELECT *,但它沒有權限。 – Dany

1

你會通過他們必須循環和取消不必要的

+0

沒有辦法來過濾? – Dany

+0

不,沒有... – genesis

+0

也許是FQL查詢,但我沒有用它 – genesis