简体   繁体   中英

Simple application with facebook php sdk

I'm trying to build my first facebook app using php sdk. In order to get user's name, I tried this code

<?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>

But the only thing I get as html output is

<!doctype html>
<html>
  <head>
    <title>test</title>
  </head>
  <body>
 Utente   
      <img src="https://graph.facebook.com/0/picture">
  </body>
</html>

Using error_reporting(E_ALL); I'm getting

Notice: Undefined variable: user_profile in /membri/angeange/fb/test.php on line 27 ( Utente <?php echo $user_profile['name']; ?> )

What am I doing wrong?

I think this SDK are you using is deprecated.

Go to developers.facebook.com and check the new version available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM