I've used an API call since 2018 to load Events from the Facebook Graph API. Very straight forward script with a Query. In the Facebook page there are lots of events, and the query shows events. Only not events later then 2019.
And when using the variable: 'time_filter=upcoming' nothing show up even.
This is the script I use. Tokens are alright. I've also checked all this in Graph Explorer: https://developers.facebook.com/tools/explorer
/*
Facebook SDK
Facebook SDK
Facebook SDK
Facebook SDK
*/
$nowdate = strtotime(date('Y-m-d'));
$fb = new \Facebook\Facebook([
'app_id' => '****',
'app_secret' => '****',
'default_graph_version' => 'v17.0',
'default_access_token' => '****',
]);
try {
$response = $fb->get(
'/milesamersfoort/events?fields=id,start_time,name,description,cover,date&limit=200&since='.$nowdate,
_FB_TOKEN
);
} catch(FacebookExceptionsFacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$results = $response->getGraphEdge();
The endpoint you are using for events no longer exist as of mid-Sept 2023. I was having the exact same issue with older events showing up but none of the new events. I have had to redevelop a plugin I wrote for a charity website I manage to work with the New Pages on Facebook.
For over a year Facebook has been converting pages to "New Pages". When that was completed, the "events" ZPI endpoint was completely removed and will not be returning. So anything you've developed has to be redeveloped.
Having said all of this, the "events" API endpoint has been deprecated for years now and was never officially supported in recent versions. It was only a matter of time before it disappeared.
Here is what I did to get my plugin working again. There are several hoops you have to jump through.
Use the Graph API Explorer to generate a Page access token https://developers.facebook.com/tools/explorer
Use the explorer to generate your API endpoint URL.
I used the feed endpoint to get a listing of the last 10 post (using the pager parameter).
curl -i -X GET \ "https://graph.facebook.com/v18.0/<your page ID goes here>/feed?access_token=<your access token here>"
After returning a list of posts, I created an array then I searched through them (via code) to find the ones that are events. These are marked as "story" and will usually contain " has added an event" or something close to that. I basically just did an if statement for this:
foreach($fbposts as $post){
if($post->story == '<your page name> created an event.'){
$subject = $post->id;
$search = '<your page ID>_' ;
$trimmed_id = str_replace($search, '', $subject) ;
$new_ids[] = array(
'event_id' => $trimmed_id,
);
}
}
I created an array of those events, and then used the "event" API endpoint to query each one.
curl -i -X GET \ "https://graph.facebook.com/v18.0/<your event ID here>?fields=name%2Cdescription%2Cstart_time%2Ccover&access_token=<your access token here>"
Once you return your event data, you can do whatever you want with it. I used it to create a new array with all of my events information.
This is likely not the best way to do this, but it's the only way I could figure out how to get events. Facebook hasn't documented any of this or provided ways to get events, and they haven't responded to any of my support tickets.
I hope that helps!