Search code examples
facebookfacebook-graph-api

Facebook events graph API stopped working(Sep 2023)?


I am using the below URL to retrieve events on a page that I manage so that I don't need to submit an app review etc.

https://graph.facebook.com/v17.0/{page_id}/events/created/?fields=id,name,description,place,timezone,start_time,cover,ticket_uri&access_token={access_token}&limit=50

It works and has no errors, but it only returns a few results that are from years ago, the upcoming new events are all gone? Has anyone had this issue and what the reason could be?

It used to work fine and could return everything, but from yesterday something seems to have changed.


Solution

  • 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. Eventually, no events showed up at all.

    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" API 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.

    1. Use the Graph API Explorer to generate a Page access token https://developers.facebook.com/tools/explorer

    2. Use the explorer to generate your API endpoint URL.

    3. 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>"

    4. 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,
          );
      
        }
      }
      
    5. 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>"

    6. 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 in a list, and they haven't responded to any of my support tickets.

    I hope that helps!