tags:

views:

29

answers:

2

I am loading in a JSON feed from Facebook (snippet below).

{
   "data": [
      {
         "id": "115972604762",
         "from": {
            "name": "Title Here",
            "category": "Musicians",
            "id": "20274769762"
         },
         "name": "It was an amazing gig!!",
         "picture": "http://photos-h.ak.fbcdn.net/hphotos-ak-snc1/hs196.snc1/6616_115972604762_20274769762_2185148_6347071_s.jpg",
         "source": "http://sphotos.ak.fbcdn.net/hphotos-ak-snc1/hs196.snc1/6616_115972604762_20274769762_2185148_6347071_n.jpg",
         "height": 453,
         "width": 604,
         "images": [
            {

I am loading it in using $data['pics'] = json_decode(file_get_contents('https://graph.facebook.com/'. $id .'/photos'));

How would I go about echo'ing out the from->name value to get the 'Title Here' value?

A: 

First thing I would do is var_dump() the response, that would explain the exact structure of how PHP has decoded it. My guess is that $response['data']['from']['name'] might work.

Fosco
A: 

I think it should just be this:

$array = json_decode(file_get_contents('https://graph.facebook.com/'. $id .'/photos'));
echo $array["data"]["from"]["name"];

You can echo out the array using print_r($array) and then see the structure of your php array if it didn't work as expected.

Andy Groff
I get a PHP error for that. I tried to print_r and got this: http://gist.github.com/632887
Plasticated
ahh, its because its decoding as an object. Try: echo $array->data[0]->from->name;
Andy Groff
Thank you! Sorry, I didn't realise the object thing would change how the data was accessed.
Plasticated
No problem. is it working?
Andy Groff