this is a two part question. First, I have code to make a call to graph.facebook.com with parameters that the user can enter. This returns a json when called.
The code is below:
$RAW_DATA = json_decode(file_get_contents($URL_FINAL));
If I go to the URL in my browser everything is fairly organized but if I use a var_dump() it looks like there are extra fields not shown in the browser, is there something wrong with my decoding or is it var_dump() showing things that I don’t see on my browser?
Second, after retrieving the JSON trying to access the subfields of data within it have proven to be problem.
For example:
{
"data": [
{
"id": "11111111_111111111",
"from": {
"name": "John",
"id": "111111111"
},
"story": "John shared We Are Change's photo.",
"picture": "http://photos-e.ak.fbcdn.net/hphotos-ak-prn1/35552_10151311513538690_352701444_s.jpg",
"link": "http://www.facebook.com/photo.php?fbid=10151311513538690&set=a.10150159213018690.338979.86518833689&type=1",
"name": "Timeline Photos",
"caption": "Happy election day everybody!",
"properties": [
{
"name": "By",
"text": "We Are Change",
"href": "http://www.facebook.com/WeAreChange.org?ref=stream"
}
]
}
This is what the URL returns, how would I pull just the ‘story’ from this?
I have tried several different syntax styles but the only one that returns anything is $RAW_DATA->{'data'}; and this just prints ‘Array’. As soon as I try to go into the next layer I can’t get anything to print.
That’s because “data” is an array of objects (or associative arrays).
Would work if you always knows it only has one element, otherwise you should loop through $RAW_DATA->{‘data’}.
Or to simplify: