Facebook API - return friends list (PHP arrays) -



Facebook API - return friends list (PHP arrays) -

im trying homecoming friend list of user using facebook app without using php sdk. have managed homecoming users name, gender, etc. without using auth code. im trying homecoming list of names users friends, ive managed far print array, cant seem print name laid out differently users name, gender, etc. managed echo doing:

$user->name

but when seek friends list doesnt work , doesnt echo @ all, wondering if knew how go doing this?

using print_r following:

array( [0] => array ( [name] => friend's name [id] => x ) [1] => array ( [name] => friend's name [id] => x ) [2] =>....)

until of friends have been listed.

{ "name": "name", "hometown": { "id": "hometown_id", "name": "hometown" }, "id": "friend_id" }

above construction of array of each, think potential issue not has hometown set may why i'm receiving foreach error?

given array structure, it's pretty simple(in php) want. recommend reading php's manual on arrays.

just seek this:

foreach ($array $inner_array) { echo $inner_array['name'] . "<br />"; }

aside that, be...

echo $your_array[0]['name']; echo $your_array[1]['name'];

and on , fourth..

update:

what looking not array, javascript object. referred json: javascript object notation.

you need special parser interpret array: json_decode(), comes shipped php greater or equal 5.2.0. create array associative, must pass sec parameter, boolean, true. defaults false otherwise. illustration of usage:

$json = '{ "name": "name", "hometown": { "id": "hometown_id", "name": "hometown" }, "id": "friend_id" }'; $json_arr = json_decode($json,true); foreach ($json_arr $key => $var) { if (!is_array($var)) { if ($key == 'name') { echo $var . "<br />"; } } }

update 2:

foreach ($json_arr $key => $var) { if (!is_array($var)) { if ($key == 'name') { echo "name: " . $var . "<br />"; } } else { if ($key == 'hometown') { echo "hometown: " . $var['name'] . "<br />"; } } }

the above should need.

php facebook facebook-graph-api

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -