Reputation: 1
I have a working PHP script witch shows the events from a facebook page. The problem is that is showing only the last one added event. This event has yet to start. All the other events in the past are not showed for some reasen. Any ideas why? I would like to show ALL events, including the ones in the past.
<?php
require 'facebook-api/src/facebook.php';
date_default_timezone_set('Europe/Amsterdam');
$facebook = new Facebook(array(
'appId' => '*APP-ID*',
'secret' => '*SECRET-KEY*',
'cookie' => true, // enable optional cookie support
));
try{
$events=$facebook->api('/*PAGE-ID*/events?access_token=*ACCES-TOKEN*');
}catch (FacebookApiException $e){
error_log($e);
}
foreach ($events["data"] as $event){
$startTime=strtotime($event["start_time"]);
try{
$ev=$facebook->api('/'.$event["id"]);
}catch (FacebookApiException $e){
error_log($e);
}
?>
<h2 class="head2"><?php echo $event['name']; ?></h2>
<img src="https://graph.facebook.com/<?php echo $event["id"]; ?>/picture?type=large" width="300">
<p><b>Description:</b> <br><?php echo substr( $ev["description"] ,0,250);?></p><br>
<b>When:</b> <br><?php echo date("l jS \of F Y",strtotime($event["start_time"])); ?><br><br>
<b>Time:</b> <br><?php echo date("h:i A",strtotime($event["start_time"])); ?> - <?php echo date("h:i A",strtotime($event["end_time"])); ?><br><br>
<?php
}
?>
Upvotes: 0
Views: 136
Reputation: 19
Try this
if ((time()-$startTime)<=60*60*24*365 || $startTime>time()){
try{
$ev=$facebook->api('/'.$event["id"]);
}catch (FacebookApiException $e){
error_log($e);
}
?>
Specify a date range. See the datetimediff php documentation http://php.net/manual/en/datetime.diff.php and also check the dateinterval article https://www.php.net/manual/en/dateinterval.format.php
Upvotes: 1