Reputation:
Below is the JSON code i got after logging in with Facebook. How can extract data from this JSON ? I tried the following ones, but not working.
$user = json_decode(file_get_contents($graph_url));
stdClass Object ( [id] => 725426940865193 [email] => [email protected] [first_name] => Gijo [gender] => male [last_name] => Varghese [link] => https://www.facebook.com/app_scoped_user_id/725426940865193/ [locale] => en_GB [name] => Gijo Varghese [timezone] => 5.5 [updated_time] => 2014-09-27T13:47:05+0000 [verified] => 1 )
echo $user['email']; //not working
Upvotes: 0
Views: 62
Reputation: 219824
It's an object, not an array. You need to use object syntax:
echo $user->email;
If you want to access it as an array you must pass true
as the second parameter to json_decode()
:
$user = json_decode(file_get_contents($graph_url), true);
echo $user['email'];
Upvotes: 4