filtering events from graph api facebook
I need to get all events of an user, but from now. I'm using facebook api sdk v3.0
this is my code:
if ($user) {
try {
$events = $facebook->api("/me/events");
} catch (FacebookApiException $e) {
开发者_运维百科 echo ($e);
}
}
You can run a FQL query similar to something like:
SELECT eid, name, start_time, end_time
FROM event
WHERE eid IN (SELECT eid
FROM event_member
WHERE uid = me())
and start_time > now()
This will require the user_events
extended permission.
Full example:
<!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>
you'll have to loop through them and unset unwanted
精彩评论