php 如何从一篇文章中获取 Facebook 点赞、分享、评论数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6137414/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fetch facebook likes, share, comments count from an article
提问by praneeth
I need to fetch facebook likes,share, comments count from an article
我需要从一篇文章中获取 Facebook 喜欢、分享、评论数
Is there any way to fetch facebook (likes,share, comments) count.
有什么方法可以获取 facebook (likes, share, comments) 计数。
Thanks in advance.
提前致谢。
回答by freedev
Actually you can have a more detailed report using FQL. Try following query:
实际上,您可以使用 FQL 获得更详细的报告。尝试以下查询:
- SELECT url, normalized_url, share_count, like_count, comment_count, total_count, commentsbox_count, comments_fbid, click_count FROM link_stat WHERE url = 'www.apple.com'
- 选择 url、normalized_url、share_count、like_count、comment_count、total_count、commentsbox_count、comments_fbid、click_count FROM link_stat WHERE url = 'www.apple.com'
Here the php code:
这里的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));
And this is the expected result:
这是预期的结果:
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
)
)
回答by praneeth
This solution worked for me:
这个解决方案对我有用:
<?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);
回答by love
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>";
}
回答by vsingh
Using Graph API as FQL is deprecated, The 101.. you see in the url is the article id
不推荐使用 Graph API 作为 FQL,您在 url 中看到的 101.. 是文章 ID
https://developers.facebook.com/tools/explorer