I'm not sure you've implemented or not but your code is missing-
User Login/Authentication
The code is not authenticating the user. After creating the
$fb
object; use this-$user_id = $fb->getUser(); if($user_id) { try { // proceed your api calls - user is authenticated at this point } catch(FacebookApiException $e) { $login_url = $fb->getLoginUrl(array( 'scope' => 'manage_pages')); header ("Location: $login_url"); error_log($e->getType()); error_log($e->getMessage()); } } else { $login_url = $fb->getLoginUrl(array( 'scope' => 'manage_pages')); header ("Location: $login_url"); }
Permissions
The documentation says-
For the page events-
- Any access token can be used to view publicly shared events.
- A
user access token
is required to retrieve events visible to that person. - A
page access token
is required to retrieve any other events.
I think you are trying to fetch all the events in a page, so you'll be needing the page access token.
To get a page access token:
$fb->api("/PAGE_ID?fields=access_token");
. Use the token return with your original call to get all the page's events-$page_events = $fb->api('/PAGEID/events?access_token='.$page_access_token.'&fields=description,location,name,owner,cover,start_time,end_time', 'GET');
(If required, you can also get a never expiring page token for a page: See here)