我尝试使用FQL和Graph API完成此操作.
我开始尝试这个FQL调用:
$fql = "SELECT pic, src_big FROM photo WHERE pid IN (SELECT pid FROM photo_tag WHERE subject = me())";
从这里我收到的结果包括包含给定用户的标签的图像(在这种情况下:me()).但是,这些图像可能包含多个标记用户.我希望通过使用SQL HAVING子句和COUNT(https://stackoverflow.com/a/3710501/1406986)解决此问题.不幸的是我不认为FQL支持这个功能,因为当我尝试这个调用时:
$fql = "SELECT pic, src_big FROM photo WHERE pid IN (SELECT pid FROM photo_tag HAVING COUNT(subject) = 1";
我从Facebook收到了一个错误.如果FQL确实支持此功能,请纠正我.
为了尝试使用Graph API解决这个问题,我提出了以下请求:
$userPics = $facebook->api('/me/photos');
这会返回用户的照片,但是,从这一点开始,我被迫迭代每张照片,寻找只包含一个标签的照片.我发现这是不切实际的,例如,如果我需要为每个只包含他们的朋友而不包含其他人的朋友找到一个图像.要做到这一点,我需要单独检索他们每个朋友的照片,然后迭代所有这些照片.
我还在寻找一个好的解决方案.请发布您的想法和解决方案.
最佳答案 好吧,我已经设法为这个问题创建了一个FQL,但它根本不是很好
SELECT object_id, pid, src_big FROM photo WHERE pid IN
(SELECT pid FROM photo_tag
WHERE pid IN (SELECT pid FROM photo_tag WHERE subject = me())
AND NOT (pid IN
(SELECT pid FROM photo_tag WHERE pid IN
(SELECT pid FROM photo_tag WHERE subject = me())
AND subject != me())
)
)
说明:
第一个非常简单,获取当前用户的photo_tags
SELECT pid FROM photo_tag WHERE subject = me()
下一个我加入了同一张桌子,但这次我想要照片,我和某人在一起
SELECT pid FROM photo_tag WHERE pid IN
(SELECT pid FROM photo_tag WHERE subject = me())
AND subject != me()
我再次加入了同一张桌子(是3张同桌的连接),但是这一次我想要photo_tags,我是主题,而不是我之前获得的列表(我和某人一起拍摄的照片) ,因此该查询返回所有photo_tags,其中用户是该照片中唯一标记的用户
SELECT pid FROM photo_tag
WHERE pid IN (SELECT pid FROM photo_tag WHERE subject = me())
AND NOT (pid IN
(SELECT pid FROM photo_tag WHERE pid IN
(SELECT pid FROM photo_tag WHERE subject = me())
AND subject != me())
)
查询的最后一个添加只是一个连接,从照片的照片表中获取信息是我唯一标记的
SELECT object_id, pid, src_big FROM photo WHERE pid IN
(SELECT pid FROM photo_tag
WHERE pid IN (SELECT pid FROM photo_tag WHERE subject = me())
AND NOT (pid IN
(SELECT pid FROM photo_tag WHERE pid IN
(SELECT pid FROM photo_tag WHERE subject = me())
AND subject != me())
)
)