建议书就像.你可以在like按钮的引用中看到它:
action- 要在按钮上显示的动词.选项:'喜欢','推荐'
要获取URL的计数(此处http://stackoverflow.com),您可以进行FQL调用:
SELECT url, share_count, like_count, comment_count, total_count
FROM link_stat WHERE url="http://stackoverflow.com"
Run Code Online (Sandbox Code Playgroud)
$fql = 'SELECT url, share_count, like_count, comment_count, total_count
FROM link_stat WHERE url="http://stackoverflow.com"';
$json = file_get_contents('https://api.facebook.com/method/fql.query?format=json&query=' . urlencode($fql));
Run Code Online (Sandbox Code Playgroud)
而$json将包含:
[
{
"url" : "http://stackoverflow.com",
"share_count" : 1353,
"like_count" : 332,
"comment_count" : 538,
"total_count" : 2223
}
]
Run Code Online (Sandbox Code Playgroud)
你在这里:
share_count :URL的共享计数like_count :喜欢的数量(=推荐)comment_count :Facebook中的评论数量低于该链接的份额total_count :这三个计数的总和您可以在PHP中阅读json json_decode:
$data = json_decode($json);
echo $data[0]->like_count;
Run Code Online (Sandbox Code Playgroud)
编辑:正如Rufinus在其答案的评论中指出的那样,出于稳定性原因,如果你是一个长期项目而不仅仅是一个快速实验,你应该使用Facebook PHP SDK(参见github)来进行FQL查询:Facebook是越来越多的关闭公共访问(没有访问令牌读取)到其API(请参阅Facebook开发者博客上的这篇博文).即使这里这些查询与任何用户无关:SDK正在使用应用访问令牌进行查询.
require "facebook.php";
$facebook = new Facebook(array(
'appId' => YOUR_APP_ID,
'secret' => YOUR_APP_SECRET,
));
$fql = 'SELECT url, share_count, like_count, comment_count, click_count, total_count
FROM link_stat WHERE url="http://stackoverflow.com"';
$result = $facebook->api(array(
'method' => 'fql.query',
'query' => $fql,
));
Run Code Online (Sandbox Code Playgroud)
该$result数组包含您需要的内容(like_count字段)甚至更多:
Array (
[0] => Array (
[url] => http://stackoverflow.com
[share_count] => 1356
[like_count] => 332
[comment_count] => 538
[click_count] => 91
[total_count] => 2226
)
)
Run Code Online (Sandbox Code Playgroud)