3

我正在使用 facebook connect 和 facebook 社交插件评论 ( )。我想从当前页面获取评论计数。怎么写?需要使用 FQL 吗?如果fql,

SELECT count(*) FROM comments WHERE xid= ?

我应该添加什么xid?如何从当前地址获取 xid ?

4

2 回答 2

5
<?php
session_start();

$fbconfig['appid' ]  = "1111111";
$fbconfig['api'   ]  = "2222222";
$fbconfig['secret']  = "3333333";

$xid = 'myCommentBox'; 

include_once "facebook.php";

$facebook = new Facebook(array(
    'appId'  => $fbconfig['appid' ],
    'secret' => $fbconfig['secret'],
    'cookie' => true,
));

$fql = "SELECT count FROM comments_info WHERE app_id = '".$fbconfig['appid' ]."' AND xid = '$xid' ";
$param  =   array(
    'method'    => 'fql.query',
    'query'     => $fql,
    'callback'  => ''
);
$fqlResult   =   $facebook->api($param);
print_r( $fqlResult );
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Count FB comment!</title>
    </head>
<body>
<div id="fb-root"></div>
   <script src="http://connect.facebook.net/en_US/all.js#appId=<?=$fbconfig['appid' ]?>&amp;xfbml=1"></script>
   <fb:comments xid="<?=$xid?>" numposts="10" width="600" publish_feed="true"></fb:comments>
</body>
</html>
于 2011-02-02T11:55:20.587 回答
0

您只需要通过提供您的应用 id 来查询 comments_info,它将返回 xid 和特定于特定 xid 的计数。

于 2011-02-02T12:11:54.467 回答