简单的应用程序与facebook php sdk


Simple application with facebook php sdk

我正在尝试使用php sdk构建我的第一个facebook应用程序。为了获得用户名,我尝试了以下代码

<?php
require 'src/facebook.php';
$facebook = new Facebook(array(
  'appId'  => '',
  'secret' => '',
));
$user = $facebook->getUser();
$access_token = $facebook->getAccessToken();
if ($user) {
  try {
    $user_friendList = $facebook->api('/me/friends?access_token='.$access_token);
     $user_profile = $facebook->api('/me','GET');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}
?>
<!doctype html>
<html>
  <head>
    <title>test</title>
  </head>
  <body>
  Utente <?php  echo $user_profile['name']; ?>
      <img src="https://graph.facebook.com/<?php echo $user; ?>/picture">
  </body>
</html>
但是我得到的唯一html输出是
<!doctype html>
<html>
  <head>
    <title>test</title>
  </head>
  <body>
 Utente   
      <img src="https://graph.facebook.com/0/picture">
  </body>
</html>

使用error_reporting(E_ALL);我得到

注意:未定义变量:user_profile in/membri/angeange/fb/test.php on line 27 (Utente <?php echo $user_profile['name']; ?>)

我做错了什么?

我认为您正在使用的SDK已弃用。

到developers.facebook.com查看可用的新版本