Decoding json string from facebook graph api explorer in php -


i using graph api profile picture of facebook app user specified width , height.

the url: http://graph.facebook.com/'.$userid.'/picture?width=180&height=220

this return in json { "data": { "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-frc1/c0.0.553.676/s320x320/998591_136374463234627_573810314_n.jpg", "width": 262, "height": 320, "is_silhouette": false } }

i wish know how decode in php , appropriately how 'url' in json string returned. helping. note: i'll store url in variable in php, use url imagecreatefromjpeg(gd library) , use image , merge image.

use json_decode function (http://php.net/manual/en/function.json-decode.php)

it accepts json string parameter , returns either array or object

$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; $obj = json_decode($json); $array = json_decode($json, true); 

then, access values like

echo $obj->a; echo $array['a']; 

both output

1

in case can access url way

$obj = json_decode($your_fb_result); echo $obj->data->url; 

or

$array = json_decode($your_fb_result, true); echo $array['data']['url']; 

specific situation,

$response = file_get_contents('http://graph.facebook.com/'.$userid.'/picture?width=180&height=220&redirect=false'); $array = json_decode($response, true); echo $array['data']['url']; 

see http://php.net/manual/en/function.file-get-contents.php


Comments