只需使用两个查询并用您选择的编程语言进行交集。
SELECT subject, pid FROM photo_tag WHERE subject = me()
SELECT pid, subject FROM photo_tag WHERE subject IN (SELECT uid2 FROM friend WHERE uid1=me())
批处理这两个调用
fql?q={"userphotos":"SELECT subject, pid
FROM photo_tag
WHERE subject = me()",
"friendphotos":"SELECT pid, subject
FROM photo_tag
WHERE subject IN
(SELECT uid2 FROM friend WHERE uid1=me())"}
然后在你的编程语言中做这两组的交集。
a0 = data['data'][0]['fql_result_set']
a1 = data['data'][1]['fql_result_set']
例如在 Python 中,一些简单的东西
>>> photos = {}
>>> for p in a0:
... for q in a1:
... if p['pid'] == q['pid']:
... pid = p['pid']
... if pid in photos:
... photos[pid].append(p['subject'])
... else:
... photos[pid] = [q['subject']]
... photos[pid].append(p['subject'])
照片将给出一个字典,每个键都有一个 id 列表作为值。只需取其中的 10 个并将其提供给photo
表 FQL 调用
在带有模块的 Python 中,facepy
它可能看起来像
photoquery = 'SELECT pid, src_big FROM photo WHERE '+
'pid ='+pid1+' OR
'pid ='+pid2+' OR
...
graph.fql(photoquery)
总体上最慢的部分将是对朋友的 photo_tag 查询。
SELECT pid, subject FROM photo_tag WHERE subject IN (SELECT uid2 FROM friend WHERE uid1=me())