我正在尝试在我的网站上显示来自公共群组的最新群组帖子,并且我正在使用以下代码来显示原始数据,效果很好。
try {
$response = $fb->get('25366400942/feed?fields=message,updated_time,from');
$graphEdge = $response->getGraphEdge();
} 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;
}
foreach ($graphEdge as $content){
echo $content . "<br><br>";
}
使用上面的代码,我得到如下内容:
{"message":"This is a Facebook group message.","updated_time":"2016-01-10T11:27:09+0000","from":{"name":"John Doe","id":"10208143097521312"},"id":"25366400942_10153729825005943"}
我的问题是尝试格式化输出时。我可以使用 $content['message'] 和 $content['id'] 轻松显示消息和 ID,但是当我尝试使用 $content['updated_time'] 显示日期时,代码会停止,就像字段没有不存在。我还尝试使用 strtotime 和 new DataTime 转换为日期,但这只会创建一个空日期。
那我做错了什么?显然有一个名为 updated_time 的字段,它显然有一个值,那为什么我不能提取数据呢?