-1

如何使用 PHP api 获取用户所有照片的 facebook 喜欢总数有什么建议?

4

2 回答 2

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";

 ?>
于 2013-01-10T11:45:53.800 回答
0

我想这可以通过查询photoFQL 表并查找 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
                        )

                )
        )
)

从这里开始,应该是一个直接的循环来获取最多喜欢的照片。


更新:基于@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
于 2013-01-10T13:43:25.400 回答