您可以使用FQL,使您的查询:
$fql = 'SELECT total_count FROM link_stat WHERE url="http://google.com"';
$json = file_get_contents('https://api.facebook.com/method/fql.query?format=json&query=' . urlencode($fql));
$data = json_decode($json);
echo $data[0]->total_count;
这里,total_count
为您提供链接的份额数。
如果你有几个网址查询,您可以通过使用OR
使所有的,在只有一个查询:
SELECT url, total_count FROM link_stat WHERE url="..." OR url="..."
下面是一个例子是你想要得到的股份论文3个网址的数量:
$urls = array(
"http://www.example.com/page1.php?sid=2",
"http://www.example.com/page1.php?sid=12",
"http://www.example.com/page1.php?sid=34",
);
function wrap($url) {
return 'url="' . $url . '"';
}
$fql = 'SELECT url, total_count FROM link_stat WHERE ';
$fql .= implode(" OR ", array_map("wrap", $urls));
$json = file_get_contents('https://api.facebook.com/method/fql.query?format=json&query=' . urlencode($fql));
$data = json_decode($json);
而且$data
是3个对象的与每个URL的份数的数组:
array(4) {
[0]=> object(stdClass)#2 (2) {
["url"]=> string(17) "http://www.example.com/page1.php?sid=2"
["total_count"]=> int(1318598)
}
[1] => ...
[2] => ...
[3] => ...
}
然后你只需要通过数组来完成一笔数额。
希望有帮助!