FB.Event.subscribe('comment.create',
function(response) {
onCommentCreate(response.commentID,response.href); //Handle URL on function to store on database
alert(response.href); //it gives you url
}
);
function onCommentCreate(commentID,href) {
$.ajax({
type: 'POST',
url: 'handlecomment.php',
data: {commentid:commentID,href:href},
success: function(result)
{
alert(result);
}
});
}
//hadlecomment.php
<?php
error_reporting(E_ERROR);
$commentid=$_POST['commentid'];
$url=$_POST['href'];
$pid=substr($url,strpos($url, 'comments')+8);
// 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('php-sdk/facebook.php');
$config = array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
$accesstoken=$facebook->getAccessToken();
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 {
$facebook->setAccessToken($accesstoken);
$fql = 'SELECT text from comment where id = ' . $commentid;
$ret_obj = $facebook->api(array(
'method' => 'fql.query',
'query' => $fql,));
$comment= $ret_obj[0]['text'] ;
$insert_comment="insert into comments(pid,comment) values($pid,$comment)";
mysql_query($insert_comment);
} 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>';
}
?>
?>
//YOu need to set data-href of comment should be look like this...
//i am using more comments on my website so i looped through to add comment
while($result=mysql_fetch_assoc(mysql_query($query)))
{
$pic_id=$result['pic_id']; // i have saved unique pic id in my database for all images so i am
//retrieving that here
<div class="fb-comments" style=' position:relative;left:55px;top:10px;' data-href="<?php echo 'http://www.lpuphotography.edulogics.in/votography.php/comments' . $pic_id; ?>" data-width="470" data-num-posts="2"></div>
}
//if you are using single comment
<div class="fb-comments" style=' position:relative;left:55px;top:10px;' data-href="<?php echo 'http://www.lpuphotography.edulogics.in/votography.php/comments101' ?>" data-width="470" data-num-posts="2"></div>
//101 is comment id , u can set what ever you want
看起來很有希望。雖然有很多的閱讀,你能提供一個例子,尤其是收集評論數量嗎? – 2by 2012-02-19 22:16:43