列出有关facebook用户的信息

时间:2013-10-29 19:42:42

标签: php facebook

我正在尝试做什么:

  1. 用户访问我的网站。

  2. 用户通过Facebook登录

  3. 网站列出了有关用户的信息:

  4. 姓名:John simpsons

    爱好:足球,计算机

    最喜欢的电视节目:皇后之王,我如何认识你的母亲

    最喜欢的电影:初始

    生日:1983年4月12日

    现在的城市:纽约

    Etc:etc

    我现在得到了什么:

    <?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>';
    
        }
    
      ?>
    

    这样写用户名如下:

    姓名:John Simpsons

    但我希望能够写下我上面提到的更多信息,例如用户笨蛋,最喜欢的动作等。

    我对如何做到这一点的想法?我一直试图谷歌它,但无法找到任何关于它。

0 个答案:

没有答案