我在下面的示例中运行了以下示例: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查询,而不是我的用户信息?
答案 0 :(得分:0)
您需要查询pages表而不是用户,并使用page_id。查看此页面上的示例部分:https://developers.facebook.com/docs/reference/fql/page如果您需要帮助,请告诉我们:)
链接的第一个例子:
SELECT ... FROM page WHERE page_id = A