我正在使用facebook connect和facebook social plugin comment()。我想从当前页面获得评论数。怎么写呢?需要使用FQL吗?如果是fql,
SELECT count(*) FROM comments WHERE xid= ?
我应该添加什么xid?如何从当前地址获取xid?
答案 0 :(得分: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' ]?>&xfbml=1"></script>
<fb:comments xid="<?=$xid?>" numposts="10" width="600" publish_feed="true"></fb:comments>
</body>
</html>
答案 1 :(得分:1)
您只需通过提供您的应用ID来查询comments_info,它将返回特定xid特定的xid和计数。