1

我正在尝试在我的网站上显示来自公共群组的最新群组帖子,并且我正在使用以下代码来显示原始数据,效果很好。

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 的字段,它显然有一个值,那为什么我不能提取数据呢?

4

1 回答 1

0

updated_time该数组中的键是一个DateTime对象,请查看GraphGroup类。您可以这样做$group = $response->getGraphGroup(),然后var_dump($group)以更好的格式查看响应。

于 2016-07-04T18:10:51.910 回答