从Facebook用户信息获取真实信息

时间:2012-11-30 03:10:11

标签: php parsing facebook-graph-api get userinfo

我已经在Google上阅读了官方文档和大量文档。 我想打印用户信息,但是当我运行我的代码时,我得到了这个:

Array
(
[id] => xxxx
[name] => Vinicius 
[first_name] => Vinicius
[last_name] => M
[link] => http://www.facebook.com/xxx
[username] => vinicius
[birthday] => 01/04/1989
...

我的代码是,获取用户信息:

//if user is logged in and session is valid.
if ($user){
//get user basic description
$userInfo = $facebook->api("/$user");

并表示:

<?php d($userInfo);  ?>

我想像这样打印(或类似的东西):

Name: Vinicius
Last name: M
Birthday: 01/04/1989

我遵循了Thinkdiff教程。来自他们的大量代码。

嵌套数组怎么样?

[location] => Array (
    [id] => 110703698957912
    [name] => Campinas, Sao Paulo 
)

1 个答案:

答案 0 :(得分:2)

试试这个:

echo 'First name: ' . $userInfo['first_name'];
echo 'Last name: ' . $userInfo['last_name'];
echo 'Birthday: ' . $userInfo['birthday'];

对于嵌套数组,如:

[location] => Array (
    [id] => 110703698957912
    [name] => Campinas, Sao Paulo 
)

您可以通过以下方式访问它们:

$userInfo['location']['id'];
$userInfo['location']['name'];