我需要从文章
中获取Facebook喜欢,分享,评论数量有没有办法获取Facebook(喜欢,分享,评论)数。
提前致谢。
答案 0 :(得分:27)
实际上,您可以使用FQL获得更详细的报告。 请尝试以下查询:
这里是php代码:
$fql = "SELECT url, normalized_url, share_count, like_count, comment_count, ";
$fql .= "total_count, commentsbox_count, comments_fbid, click_count FROM ";
$fql .= "link_stat WHERE url = 'www.apple.com'";
$apifql="https://api.facebook.com/method/fql.query?format=json&query=".urlencode($fql);
$json=file_get_contents($apifql);
print_r( json_decode($json));
这是预期的结果:
Array
(
[0] => stdClass Object
(
[url] => www.apple.com
[normalized_url] => http://www.apple.com/
[share_count] => 355693
[like_count] => 500374
[comment_count] => 290890
[total_count] => 1146957
[commentsbox_count] => 2
[comments_fbid] => 388265801869
[click_count] => 16558
)
)
答案 1 :(得分:5)
这个解决方案对我有用:
<?php
$source_url = "http://www.flightpodcast.com/episode-6-john-bartels-qantas-qf30";
$url = "http://api.facebook.com/restserver.php?method=links.getStats&urls=".urlencode($source_url);
$xml = file_get_contents($url);
$xml = simplexml_load_string($xml);
echo "Share --- ".$shares = $xml->link_stat->share_count;
echo "<br/>";
echo "Like --- ".$likes = $xml->link_stat->like_count;
echo "<br/>";
echo "Comments ---".$comments = $xml->link_stat->comment_count;
echo "<br/>";
echo "Total --- ".$total = $xml->link_stat->total_count;
echo "<br/>";
echo $max = max($shares,$likes,$comments);
答案 2 :(得分:1)
result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$photoid = $row['photoid'];
$likes = $facebook->api("/$photoid/likes");
echo "<br><br>".$row['photoid'];
echo "<br />";
foreach ($likes['data'] as $like)
{
$likeid = $like['id'];
$name = $like['name'];
echo "<br>like : ".$like['id']." , ".$like['name'];
$query = sprintf("INSERT INTO photo_like VALUES (%s,%s,'%s')",$user_id,$likeid,$name);
echo "<br>query string : ".$query."<br><br>";
$result = mysql_query($query);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
echo "<br>";
}
答案 3 :(得分:0)