我正在尝试通过Facebook图形api检索信息,使用下面的代码,它没有给我任何回报,我在获得在线文档的帮助后编写了这段代码等但是它没有用。
请帮助我。
include ('src/facebook.php');
$app_id = "160336957418730";
$app_secret = "************************";
$facebook = new Facebook( array('appId' => $app_id, 'secret' => $app_secret, ));
$user = $facebook -> getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook -> api('/me');
//$user_profile = $facebook->api('/me/home');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
echo $user_profile[name];
echo $user_profile[id];
echo $user_profile[picture];
我对他们感到沮丧,但没有任何工作。
答案 0 :(得分:2)
您需要从user_profile数组中回显。尝试下面$ user_profile [name];它很奇怪,没有引号来串联,但这就是我们访问数组的方式。
include ('src/facebook.php');
$app_id = "160336957418730";
$app_secret = "************************";
$facebook = new Facebook( array('appId' => $app_id, 'secret' => $app_secret, ));
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
//$user_profile = $facebook->api('/me/home');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
echo $user_profile[name];
echo $user_profile[id];
echo $user_profile[picture];