PHP:Facebook Event API start_time不显示今天的事件

时间:2013-11-20 22:02:36

标签: php sql facebook date facebook-fql

我正在将Facebook事件发送到我的网站,但是有一个问题,即今天的事件会在一天之前消失。如果今天有活动,今天它将不会显示在我的网站上。今天00:00,活动从视野中消失。

我使用以下代码:

<?php

//we have to set timezone to California
date_default_timezone_set('California');

//requiring FB PHP SDK
require 'fb-sdk/src/facebook.php';

//initializing keys
$facebook = new Facebook(array(
        'appId'  => 'APP_ID',
        'secret' => 'APP_SECRET',
        'cookie' => true, // enable optional cookie support
));

$fql    =   "SELECT eid, name, pic, start_time, end_time, location, description, attending_count FROM event WHERE eid IN ( SELECT eid FROM 
event_member WHERE uid = PAGE_ID) AND start_time >= now() ORDER BY start_time ASC";
$param  =   array(
'method'    => 'fql.query',
'query'     => $fql,
'callback'  => ''
);

$fqlResult   =   $facebook->api($param);

//looping through retrieved data
foreach( $fqlResult as $keys => $values ) {

        $start_date = date( 'l, F d, Y', $values['start_time'] );
        $end_date = date( 'l, F d, Y', $values['end_time'] );

        $start_time = date( 'g:i a', $values['start_time'] );
        $end_time = date( 'g:i a', $values['end_time'] );

        $time = explode("T", $values['start_time']);
        $tid = explode("+", $time[1]);

        if ($time[0] > date("Y-m-d"))
        {

                //printing the data
                echo "<div class='event'>";
                echo "<div>";

                        echo "<table><tr><td valign='top'>";
                        echo "<img src={$values['pic']} width='100px' />";
                        echo "</td><td valign='top'>";

                        echo "<span style='font-family:verdana;font-size:10pt;'><b>" . $values['name'] . "</b></span><br>";
                        echo "<span style='font-family:verdana;font-size:9pt; color:#666666; line-height:7pt;'>".$time[0]." kl ".substr($tid[0],0,5)."<br>";
                        echo "Place: " . $values['location'] . "<br>".$values['attending_count']. " attendings.<br>";
                        echo "<a href='https://www.facebook.com/events/".$values['eid']."/' target='_blank'><br>More info</a></span>";

                        echo "</td></tr></table><br>";

                echo "</div>";
                echo "</div>";
        }

}

?>

date_default_timezone_set('America/Los_Angeles');不起作用。

有谁知道为什么? 提前谢谢。

更新 - &gt;解

if ($time[0] > date("Y-m-d"))更改为if ($time[0] >= date("Y-m-d")),它将显示今天的事件。

1 个答案:

答案 0 :(得分:0)

如果使用FQL函数now(),则不会获得今天开始且在当前时间之前的事件。而是使用您自己的变量$now而不是函数now()

$now = strtotime('today');
$fql = "SELECT ... WHERE ... start_date >= $now ...";

返回的时间戳(start_dateend_date)是UTC时区,因此如果您希望在您的时区格式化:

$start = new DateTime('@'.$values['start_time']);
$start->setTimezone(new DateTimezone('America/Los_Angeles'));
$start->format('Y-m-d H:i:s');

您还应该看一下这个链接:Platform Migration: Events Timezone Support