我如何访问Facebook页面而不是我自己的FQL数据?


How do I access FQL data for a Facebook page rather than my self?

我从Facebook的例子中得到了下面的例子:

    <?php
    ini_set('display_errors','On');
    error_reporting(E_ALL);
  // 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('facebook-php-sdk-master/src/facebook.php');
  $config = array(
    'appId' => 'appid',
    'secret' => 'secret',
  );
  $facebook = new Facebook($config);
  $user_id = $facebook->getUser();


?>
<html>
  <head></head>
  <body>
  <?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 {
        $fql = 'SELECT name from user where uid = ' . $user_id;
        $ret_obj = $facebook->api(array(
                                   'method' => 'fql.query',
                                   'query' => $fql,
                                 ));
        // 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>';
      } 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>

我如何修改这一点,这样我就可以使一个FQL查询到我的FB页面之一,而不是我的用户信息?

您需要查询pages表而不是用户,并使用page_id。查看本页的示例部分:https://developers.facebook.com/docs/reference/fql/page,如果你需要帮助来理解它们,请告诉我:)

链接中的第一个例子:

SELECT ... FROM page WHERE page_id = A