2013-01-10 46 views

回答

0

我想這是可能通過查詢photo FQL表,並尋找like_info結構,專爲LIKE_COUNT。因此像下面的查詢應該工作:

SELECT object_id, album_object_id, like_info.like_count FROM photo WHERE album_object_id IN (
    SELECT object_id FROM album WHERE owner = me() 
) 

這將返回類似:

Array 
(
    [data] => Array 
     (
      [0] => Array 
       (
        [object_id] => XXX 
        [album_object_id] => YYY 
        [like_info] => Array 
         (
          [like_count] => 7 
         ) 

       ) 

      [1] => Array 
       (
        [object_id] => XXX 
        [album_object_id] => YYY 
        [like_info] => Array 
         (
          [like_count] => 9 
         ) 

       ) 

      [2] => Array 
       (
        [object_id] => XXX 
        [album_object_id] => YYY 
        [like_info] => Array 
         (
          [like_count] => 1 
         ) 

       ) 
     ) 
) 

從這裏,它應該是一個簡單的循環,以獲得照片(S)具有最高號的喜歡。


更新:基於@cpilko此外,這應該工作:

SELECT object_id, album_object_id, like_info.like_count FROM photo WHERE album_object_id IN (
    SELECT object_id FROM album WHERE owner = me() 
) ORDER BY like_info.like_count DESC LIMIT 1 
+0

在@ ifaour的查詢結尾添加'ORDER BY like_info.like_count DESC LIMIT 1',您將只獲得喜歡數量最多的照片。 – cpilko

+0

你也可以將原始查詢簡化爲'SELECT object_id,album_object_id,like_info.like_count FROM photo WHERE owner = me()' – cpilko

+0

我沒有建議短版本,因爲它不檢索所有的照片...我猜標記的照片不包括在內 – ifaour

1

我的做法是這樣:

<?php 
// the url to check how many likes 
$url = 'url of image'; 
// build the facebook query 
$fburl = "http://api.facebook.com/method/fql.query?query=select%20like_count%20from%20link_stat%20where%20url='$url'&format=atom"; 
// grab the atom dump via facebook api url call above 
$ch = curl_init($fburl); // url for page 
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); 
$atom_data = curl_exec($ch); 
// it returns something like this: 
/* <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true"> 
<link_stat> 
<like_count>9</like_count> 
</link_stat> 
</fql_query_response> */ 
preg_match('#like_count>(\d+)<#',$atom_data,$matches); 
$like_count = $matches[1]; 
echo "The image has ".$like_count." likes on facebook"; 



// OPTION 2 >>> keeping it to a 1 liner: 
$data = json_decode(file_get_contents("http://api.facebook.com/method/fql.query?query=select%20like_count%20from%20link_stat%20where%20url='$url'&format=json")); 
echo "The image has " . $data[0]->like_count . " likes on facebook"; 

?> 
+0

。來自所有照片的喜歡。這隻會得到一個特定的網址? –

+0

沒有具體的方法來獲得最喜歡的圖像與一個查詢/請求。你需要一個循環或一系列。爲更多參考這個http://stackoverflow.com/questions/7271029/how-to-get-page-photo-with-the-most-likes-comments。 –

+0

好的,謝謝。 –

相關問題