1

我想通过Facebook图api检索信息,使用下面的代码没有返回任何内容,我在从在线文档等获得帮助后编写了此代码,但它不工作。无法通过脸谱图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]; 

我把他们全都打包了,但没有任何工作。

回答

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]; 
+0

我更新了我的代码,但它仍然不工作?没有输出..任何可能的原因? – Maven 2012-03-24 19:31:21

+0

你有没有给你应用程序的权限来查看你的基本信息? – 2012-03-25 01:13:38