I am working with the Facebook SDK and PHP. Everything is working fine, but I am having trouble with one part, which is storing a specific field value into a variable.
Here is the code, which gets and prints the info.
if ($session){ //if we have the FB session
$user_profile = (new FacebookRequest($session, 'GET', '/me/accounts?fields=id,name,access_token'))->execute()->getGraphObject(GraphUser::className());
//do stuff below, save user info to database etc.
echo "Session Set.";
echo '<pre>';
print_r($user_profile); //Or just print all user details
$variable = print_r($user_profile, TRUE);
echo '</pre>';
// How do I get the first 'id', 'name', and 'access_token'
// How do I get the second 'id', 'name', and 'access_token'
}
And here is what prints (I replaced the actual data with XXXX for obvious reasons):
Session Set.
Facebook\GraphUser Object
(
[backingData:protected] => Array
(
[data] => Array
(
[0] => stdClass Object
(
[id] => XXXXXXXX
[name] => XXXXXXXX
[access_token] => XXXXXXXXX
)
[1] => stdClass Object
(
[id] => XXXXXXXXX
[name] => XXXXXXXXX
[access_token] => XXXXXXXXX
)
)
[paging] => stdClass Object
(
[cursors] => stdClass Object
(
[before] => XXXXXXX
[after] => XXXXXXX
)
)
)
)
How do I take [id], [name], and [access_token] and store them in variables so I can eventually save them into a db?