我试图通过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];
我把它们都试过了,但什么都不起作用。
发布于 2012-03-24 17:15:06
您需要从user_profile数组回显。尝试像下面这样的$user_profilename;没有引号作为字符串,这很奇怪,但这是我们访问数组的方式。
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];
https://stackoverflow.com/questions/9852686
复制相似问题