我目前通过以下PHP脚本获取网址的赞的数量:
<?php
$source_url = "[my-url-here]"; //This could be anything URL source including stripslashes($_POST['url'])
$url = "http://api.facebook.com/restserver.php?method=links.getStats&urls=".urlencode($source_url);
$xml = file_get_contents($url);
$xml = simplexml_load_string($xml);
$shares = $xml->link_stat->share_count;
$likes = $xml->link_stat->like_count;
$comments = $xml->link_stat->comment_count;
$total = $xml->link_stat->total_count;
$max = max($shares,$likes,$comments);
echo "$source_url
<br><br>shares: $shares
<br><br>likes: $likes
<br><br>comments: $comments
<br><br>total: $total
<br><br>max: $max
<br>------------<br>
";
?>
问题在于likes: $likes
,我不只是收到了网址的赞的数量,但我也计算了赞的数量在评论部分收到(fb脚本)。
我目前正在根据赞收到的个人资料网址的数量来管理网络竞赛,而且有些用户正在使用此方案(通过向赞成提供许多赞成他们的个人资料收到的评论),以增加他们获胜的机会。
那么,我如何才能获得网址的赞的实际数量,而不包括评论框部分中帖子收到的赞?
谢谢, 亚历
答案 0 :(得分:1)
好的,这是如何获取网址的赞的实际数量(不包括评论,评论,分享):
$source_url="http://www.google.ro"; //the url you need
//first get the total number of likes, and the comments_fbid that we will need in the next query
$fql_query_url = 'https://graph.facebook.com/'
. 'fql?q=SELECT+like_count,comments_fbid+FROM+link_stat+WHERE+url="' . $source_url . '"';
$fql_query_result = file_get_contents($fql_query_url);
$fql_query_obj = json_decode($fql_query_result, true);
//place them in 2 variables to use
$like_total=$fql_query_obj["data"][0]["like_count"];
$object_id=$fql_query_obj["data"][0]["comments_fbid"];
echo $like_total;
echo "<br>";
echo $object_id;
//execute next query from the *comment* table to get the array of *likes* in the comment section
$fql_query_url = 'https://graph.facebook.com/'
. 'fql?q=SELECT+likes+FROM+comment+WHERE+object_id=' . $object_id;
$fql_query_result = file_get_contents($fql_query_url);
$fql_query_obj = json_decode($fql_query_result, true);
//sum out the results in the array
$nr=count($fql_query_obj["data"]);
$s=0;
for($i=0;$i<$nr;$i++)
{ $s+=$fql_query_obj["data"][$i]["likes"]; }
$therealnumberoflikes=$like_total-$s;
echo $therealnumberoflikes;
答案 1 :(得分:0)
您可以尝试使用Facebook Open Graph获取赞的数量:
http://graph.facebook.com/?ids=http://www.url.com/page
另一种更精确的方法是使用FQL查询:
Facebook Query Language Reference
从link_stat
表格,使用网址 - link_stat Reference:
SELECT like_count, comments_fbid FROM link_stat WHERE url = "http://www.url.com/page"
使用likes
作为comment
- comments Reference,comments_fbid
为object_id
的每条评论获取SELECT likes FROM comment WHERE object_id = [comments_fbid]
:
likes
对每条评论中的所有like_count
求和,并将该总和减去{{1}}