0

我从此处的 Facebook 示例中运行了以下示例:facebook api docs

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

如何修改它,以便我可以对我的一个 FB 页面而不是我的用户信息进行 FQL 查询?

4

1 回答 1

0

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

链接中的第一个示例:

SELECT ... FROM page WHERE page_id = A
于 2013-05-11T05:53:09.993 回答