I'm working with the Facebook API and I'm trying to retrieve an item from jSON, but I'm not getting it.
First of all, this is the jSON that is returned to me from the Graph Facebook API .
{
"data": [
{
"message": "Boa Tarde!",
"id": "**********************************",
"created_time": "2015-09-24T19:10:13+0000"
"from": {
"name": "Diego Souza",
"id": "**************************"
},
},
{
"name": "Mensagem",
"id": "**********************************",
"created_time": "2015-08-17T19:17:50+0000"
},
{
"name": "Mensagem",
"id": "**********************************",
"created_time": "2015-07-17T13:06:12+0000"
},
{
"name": "Mensagem",
"id": "**********************************",
"created_time": "2015-07-17T12:47:06+0000"
},
{
"name": "Mensagem",
"id": "**********************************",
"created_time": "2015-07-17T12:41:41+0000"
}
],
}
I am making this code:
# Posts Facebook
$authID = "***************";
$authToken = "***************";
$urlFace = "https://graph.facebook.com/$authID/feed?fields=name,message&access_token=$authToken";
$jsonDados = file_get_contents($urlFace);
$jsonObject = json_decode($jsonDados, TRUE);
foreach ($jsonObject['data'] as $key => $value) {
print_r($value);
}
And it's returning me like this:
Array
(
[message] => Boa Tarde ! :)
[from] => Array
(
[name] => Diego Souza
[id] => **************************
)
[id] => **************************
[created_time] => 2015-09-24T19:10:13+0000
)
Array
(
[name] => Mensagem
[id] => **********************************
[created_time] => 2015-08-17T19:17:50+0000
)
Array
(
[name] => Mensagem
[id] => **********************************
[created_time] => 2015-07-17T13:06:12+0000
)
Array
(
[name] => Mensagem
[id] => **********************************
[created_time] => 2015-07-17T12:47:06+0000
)
Array
(
[name] => Mensagem
[id] => **********************************
[created_time] => 2015-07-17T12:41:41+0000
)
What I need
In this case I would like to get only messages posted by users, which would be the array message
in jSON .
I've tried this:
foreach ($jsonObject['data'] as $key => $value) {
foreach($value as $var)
echo $var;
}
But I returned all messages instead of what is in message
.
The trick is that it mounts multiple arrays. And I need arrays that contain only message
. In that case that I post has only one user post on the Facebook page. There will be more.
I need arrays that have only message
. It only complicates this Facebook.