-
Notifications
You must be signed in to change notification settings - Fork 0
/
fbevents.php
36 lines (30 loc) · 968 Bytes
/
fbevents.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
$appId = "";
$appSecret = "";
$accessToken = "";
$pageName = "";
require_once __DIR__ . '/vendor/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => $appId,
'app_secret' => $appSecret,
'default_graph_version' => 'v3.1',
'default_access_token' => $accessToken
]);
try {
$response = $fb->get('/' . $pageName . '/events');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$pageList = $response->getGraphEdge()->asArray();
$eventsList = array();
foreach ($pageList as $event) {
$event['timestamp'] = $event['start_time']->getTimestamp();
$event['start_time'] = $event['start_time']->format(DATE_ISO8601);
$event['end_time'] = $event['end_time']->format(DATE_ISO8601);
$eventsList[] = $event;
}
echo json_encode($eventsList);