Richard Stenstierna
Richard Stenstierna

Reputation: 2235

Facebook events API

I have a page on facebook and i have created a number of events on it.

I also use those events in my mobile app.

But now the graph API shows events that i have already been to.

If you go to Graph API Explorer you'll see it shows 4 events.

But the last 2 events from the bottom are the past events.

I have already added end date for them so that can't be the issue here.

What to do so that the graph API doesn't show those 2 events?

I don't want to remove them from facebook, but just want to hide it.

Please advice.

Upvotes: 1

Views: 3393

Answers (1)

Syed I.R.
Syed I.R.

Reputation: 6230

You can restrict the data returned by facebook to show only the events created after a specific date using the since query parameter which accepts a unix timestamp.

So if you want events which are created after 8th of October 2012 or any other date, you can make a call with the since query parameter, In this case the unix timestamp of 08 Oct 2012 00:00:00 GMT will be 1349654400.

Now if we make a call with the since query parameter and the above unix timestamp, It'll return all the events created after 8th of October 2012.

Here's a working call made on Graph API Explorer with the since query parameter.

In case if the above link does not work:

https://developers.facebook.com/tools/explorer?method=GET&path=jarnvags%2Fevents%3Fsince%3D1349654400

Path: jarnvags/events?since=1349654400

Let me know if this helped you :)

EDIT: Here's how to do it with FQL:

SELECT eid, name, description, pic_big, start_time, end_time, location FROM event WHERE creator = 109341359096369 AND eid IN (SELECT eid FROM event_member WHERE uid = 109341359096369) AND start_time >= now() ORDER BY start_time

And here's how you should do it in PHP:

$pageID = '109341359096369';
$fql = 'SELECT eid, name, description, pic_big, start_time, end_time, location FROM event WHERE creator = ' . $pageID . ' AND eid IN (SELECT eid FROM event_member WHERE uid = ' . $pageID . ') AND start_time >= now() ORDER BY start_time';
$ret_obj = $facebook->api(array(
                           'method' => 'fql.query',
                           'query' => $fql,
                         ));
print_r($ret_obj);

Check out event table FQL docs at: https://developers.facebook.com/docs/reference/fql/event/

EDIT 2: Just wanted to highlight the point made by cpilko below in comments so people who see this answer in future could easily notice it, You don't have to convert the date to timestamp anymore, It works with just the date as well (2012-10-08).

And here's the Events Timezone Migration Note quoted from facebook events doc:

Events Timezone Migration Note

Starting with the 'Events Timezone' migration, all event times are always ISO-8601 formatted strings; the 'date_format' query string modifier no longer has any effect. The following formats are now returned, depending on the type of event:

Date-only (e.g., '2012-07-04'): events that have a date but no specific time yet. Precise-time (e.g., '2012-07-04T19:00:00-0700'): events that start at a particular point in time, in a specific offset from UTC. This is the way new Facebook events keep track of time, and allows users to view events in different timezones. Local-time (deprecated, e.g., '2012-07-04T19:00:00'): legacy events that do not have any timezone information. This format is deprecated, but continues to be returned due to legacy events that are still in the system.

Upvotes: 3

Related Questions