我正在使用Facebook SDK和PHP。一切工作正常,但我有一個部分,這是一個特定的字段值存儲到一個變量的麻煩。Facebook SDK和PHP數組
這是獲取並打印信息的代碼。
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'
}
而這裏就是打印(I替換爲XXXX的原因很明顯的實際數據):
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
)
)
)
)
如何拍攝[ID],[名]和[的access_token]和存儲他們在變量,所以我最終可以將他們保存到一個數據庫?