1

I am trying to display the latest group posts from a public group on my website and I'm using the following code to display the raw data, which works fine.

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>";
}

With the above code i get something like the following:

{"message":"This is a Facebook group message.","updated_time":"2016-01-10T11:27:09+0000","from":{"name":"John Doe","id":"10208143097521312"},"id":"25366400942_10153729825005943"}

My problem is when trying to format the output. I can easily display the message and id by using $content['message'] and $content['id'] but when I try to display the date using $content['updated_time'] the code just stops, like the field doesn't exist. I've also tried to cast to a date using strtotime and new DataTime but that just creates an empty date.

So what am i doing wrong? There clearly is a field called updated_time and it clearly has a value, so why can't I extract the data?

JakobM83
  • 11
  • 1
  • do you manage the group? i am pretty sure you are not allowed to just show the group feed elsewhere without permission of all group members. i would not want my group posts to show up elsewhere without my permission. i am pretty sure facebook will remove this possibility sooner or later, it should actually be gone with the user_groups permission imho. – andyrandy Jan 10 '16 at 13:06
  • Yes i manage the group. Basically the group and website is for a small local sports club and everyone can view the posts on facebook but you have to be a member of the group to post. We already have a similar feature on our current website, but that is handled by Wordpress and I have no idea what the code looks like. – JakobM83 Jan 10 '16 at 13:36

1 Answers1

0

updated_time key in that array is a DateTime object, take a look to GraphGroup class. You can just do $group = $response->getGraphGroup() and then var_dump($group) to see the response in a better format.

Vasfed
  • 18,013
  • 10
  • 47
  • 53
Alcides
  • 59
  • 1
  • 4