php的Facebook Page Feed日期

时间:2018-12-19 10:34:07

标签: php facebook-graph-api facebook-php-sdk

我很难弄清楚为什么我的日期时间会在刷新浏览器时重置为当前时间。我们在页面Feed帖子的返回日期中有一个错误,日期和时间在返回1970/01/01 00:00:00,所以我从该行中删除了strotime

$page[$i]['createdtime'] = DateAndTime::SetTimeFacebookFeed('Y/m/d H:i:s',($mes["created_time"]),$timezone);

然后返回当前日期。我将功能更改为在调试中逐步执行时从时间戳返回日期,日期是正确的。当我单步执行代码时,浏览器刷新了页面,日期显示正确,但是当我关闭调试日期时,将返回当前时区-当前时间。这是我的代码:

public function SetTimeFacebookFeed($format, $timestamp, $timezone)
{
    $time = date('r',$timestamp);
    try
    {
        $dtzone = new DateTimeZone($timezone);
        $dtime = new DateTime($timestamp->date);
        $dtime->setTimeZone($dtzone);
        $mytime = $dtime->format($format);
    }

    catch(exception $e)
    {
        die($e->getMessage());
    }
    return $mytime;
}

public function ProcessPageStream($pagestream,$timezone,$accessToken)
{
    $gsFb = new gsfacabook();
    if (!empty($pagestream))
    {
        $page = array();
        $i = 0;
        foreach ($pagestream as $mes)
        {
            //$MessageInfo = $gsFb->GetMessage($mes["id"],$accessToken);
            $page[$i]['postid'] = $mes["id"];
            $page[$i]['userid'] = $mes["from"]["id"];
            $page[$i]['userimage'] = empty($mes["from"]) ? null : $gsFb->GetUsersPicture($mes["from"]["id"],$accessToken)["picture"]["url"];
            $page[$i]['username'] = $mes["from"]["name"];
            $page[$i]['message'] = $mes["message"];
            $page[$i]['createdtime'] = DateAndTime::SetTimeFacebookFeed('Y/m/d H:i:s',($mes["created_time"]),$timezone);
            $page[$i]['islink'] = 0;
            if ($mes["type"] == 'link' || $mes["type"] == 'swf')
            {
                $page[$i]['islink'] = 1;
                $page[$i]['linkpicture'] = $mes["picture"];
                $page[$i]['link'] = $mes["link"];
                $page[$i]['linkname'] = $mes["name"];
                $page[$i]['linkdescription'] =$mes["description"];
            }

            $page[$i]['isphoto'] = 0;
            if ($mes->type == 'photo')
            {
                $page[$i]['isphoto'] = 1;
                $page[$i]['photo'] = $mes["picture"];
                $page[$i]['photolink'] = $mes["link"];
                $page[$i]['photoname'] = $mes["description"];
            }
            $page[$i]['haslikes']=0;
            $page[$i]['hascomments']=0;
            if (is_array($mes["likes"]["data"]) || is_array($mes["comments"]["data"])){
            if (is_array($mes["likes"]["data"]))
            {
                $page[$i]['haslikes'] = 1;
                $page[$i]['likes'] = count($mes-["likes"]["data"]);
                $page[$i]['latestlike'] = $mes["likes"]["data"][0]["name"];
            }
            if (is_array($mes["comments"]["data"]))
            {
                $page[$i]['hascomments'] = 1;
                $page[$i]['comments'] = count($mes["comments"]["data"]);
                $c = 0;
                foreach ($mes["comments"]["data"] as $com)
                {
                    $page[$i]['commentdata'][$c]['commentid'] = $com["id"];
                    $page[$i]['commentdata'][$c]['userid'] = $com["from"]["id"];
                    $page[$i]['commentdata'][$c]['username'] = $com["from"]["name"];
                    $page[$i]['commentdata'][$c]['message'] = $com["message"];
                    $page[$i]['commentdata'][$c]['created'] = DateAndTime::SetTime('Y/m/d H:i:s',strtotime($com["created_time"]),$timezone);
                }
            }
        }
        $i++;
    }
    return $page;
}
}

0 个答案:

没有答案