duan01203 2018-12-19 10:34
浏览 29

Facebook页面发布日期的帖子php

I'm having difficulty figuring out why my date time is resetting back to current time on browser refresh. We had a bug in the date returned of the page feed posts, date and time was returning 1970/01/01 00:00:00, so I removed strotime from this line

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

And then it returns current date. I altered the function to return date from timestamp an when stepping through in debug, the date an time is correct. When I've stepped through the code an browser has refreshed the page the date shows correct, but when I turn off a debug date returns to the current time zone- current time. Here is my code:

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条回答 默认 最新

    报告相同问题?