如何在PHP SDK中使用访问令牌,并使用fql检索用户活动参数?

如何在PHP SDK中使用访问令牌,并使用fql检索用户活动参数?,php,facebook,facebook-fql,facebook-php-sdk,Php,Facebook,Facebook Fql,Facebook Php Sdk,我想知道如何使用PHP SDK中getAccessToken()获得的访问令牌 以下是我试图显示用户电子邮件id和用户活动的代码段: 当我运行此代码时,电子邮件和用户活动为空,我如何修复此问题 <?php require '/home/vespanve/public_html/facebook-php-sdk/src/facebook.php'; $facebook = new Facebook(array( 'appId' => '

我想知道如何使用PHP SDK中getAccessToken()获得的访问令牌 以下是我试图显示用户电子邮件id和用户活动的代码段: 当我运行此代码时,电子邮件和用户活动为空,我如何修复此问题

      <?php



    require '/home/vespanve/public_html/facebook-php-sdk/src/facebook.php';

    $facebook = new Facebook(array(
      'appId'  => '39653698mmmmm448',
      'secret' => 'd7681299469mmmmmmmmmmmmm',
    ));

    $config = array(
        'appId' => '39653698mmmmm448',
        'secret' => 'd7681299469mmmmmmmmmmmmm',
      );

      $facebook = new Facebook($config);
      $user_id = $facebook->getUser();
    $access_token = $facebook->getAccessToken();
    $facebook->setAccessToken($access_token);

    ?>
    <html>
      <head></head>
      <body>

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

            $fql = 'SELECT name from user where uid = ' . $user_id;
        $fqlmail = 'SELECT email from user where uid = ' . $user_id;
        $fqlact = 'SELECT user_activities from user where uid = ' . $user_id;
            $ret_obj = $facebook->api(array(
                                       'method' => 'fql.query',
                                       'query' => $fql,
                                     ));
        $ret_obj2 = $facebook->api(array(
                                       'method' => 'fql.query',
                      'access_token' => $cookie['access_token'],
                                      'query' => $fqlmail,
                                     ));
        $ret_obj3 = $facebook->api(array(
                                       'method' => 'fql.query',
                      'access_token' => $cookie['access_token'],
                                      'query' => $fqlact,
                                     ));

            // FQL queries return the results in an array, so we have
            //  to get the user's name from the first element in the array.
            echo '<pre>Name: ' . $ret_obj[0]['name'] . '</pre>';
        echo '<pre>Email: ' . $ret_obj2[0]['email'] . '</pre>';
        echo '<pre>Activities: ' . $ret_obj3[0]['user_activities'] . '</pre>';
        $facebook->destroySession();



          } 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, so print a link for the user to login
          $login_url = $facebook->getLoginUrl();
          echo 'Please <a href="' . $login_url . '">login.</a>';

        }
    ?>

      </body>
    </html>

您需要请求扩展权限:

欲了解更多信息,请点击此处:

有关此处的权限:


嘿,正在检索电子邮件,但当我尝试打印用户活动时,应用程序不会给出任何输出,只会请求验证并停止工作。
$params = array(
  'scope' => 'email, user_activities',
  'redirect_uri' => 'https://www.myapp.com/post_login_page'
);

$loginUrl = $facebook->getLoginUrl($params);