2010-06-15 167 views
3

我正在使用Facebook連接和Facebook社交插件評論()。我想從當前頁面獲取評論數量。如何寫它?需要使用FQL?如果fql,Facebook社交插件評論數

SELECT count(*) FROM comments WHERE xid= ? 

我應該添加什麼xid?如何從當前地址獲取xid?

回答

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> 
+1

-1用於<?= – Burgi 2011-10-14 14:23:23

+0

這對我正在處理的東西很有用。謝謝! – 2012-05-21 23:19:59

+0

@Burgi - '<?='非常好 - 它不是一個簡短的標籤。 – 2012-08-21 00:41:38

1

你只需要通過提供你的應用程序ID來查詢comments_info,它將返回特定於特定xid的xid和計數。

相關問題