0

我正在尝试做的事情:

  1. 用户访问我的网站。

  2. 用户通过 facebook 登录

  3. 该网站列出了有关用户的信息,如下所示:

姓名:约翰·辛普森一家

爱好:足球、电脑

最喜欢的电视节目:《王后之王》、《我是怎么认识你妈妈的》

最喜欢的电影:盗梦空间

生日:1983年,4月12日

当前城市:纽约

等:等

我现在得到的:

<?php
  // Remember to copy files from the SDK's src/ directory to a
  // directory in your application on the server, such as php-sdk/
  require_once('php-sdk/facebook.php');

  $config = array(
    'appId' => 'xxxxxxxxxxxxxxxxxxxx',
    'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  );

  $facebook = new Facebook($config);
  $user_id = $facebook->getUser();
?>

   <?php
    if($user_id) {

      // We have a user ID, so probably a logged in user.
      // If not, we'll get an exception, which we handle below.
      try {

        $user_profile = $facebook->api('/me','GET');
        echo "Name: " . $user_profile['name'];

      } catch(FacebookApiException $e) {
        // If the user is logged out, you can have a 
        // user ID even though the access token is invalid.
        // In this case, we'll get an exception, so we'll
        // just ask the user to login again here.
        $login_url = $facebook->getLoginUrl(); 
        echo 'Please <a href="' . $login_url . '">login.</a>';
        error_log($e->getType());
        error_log($e->getMessage());
      }   
    } else {

      // No user, print a link for the user to login
      $login_url = $facebook->getLoginUrl();
      echo 'Please <a href="' . $login_url . '">login.</a>';

    }

  ?>

这会像这样写用户名:

姓名:约翰·辛普森

但我希望它像我上面所说的那样写下更多信息,比如用户爱好、最喜欢的动作等。

关于我将如何做到这一点的任何想法?我一直在尝试用谷歌搜索它,但找不到任何关于它的信息。

4

0 回答 0