facebook - Fetching photos in which 2 or more people are tagged -
as title says, i'm trying fetch 10 photos in logged user , 1 or more of his/her friends tagged. i'm trying php api , fql.
i'm new fql, not new programming etc. way able achieve want dynamically building multiple queries this:
select pid, src_big photo pid in( select pid photo_tag subject = me() ) , pid in( select pid photo_tag subject = '1530195' or subject = '3612831' or subject = '6912041' or ... )
apart being ugly, slow. queries limited length shown above because fail when longer.
multi-queries didn't me because can't use 'as', sql isn't greatest strength , i'm hoping i've missed something..
there must better way! anyone?
just use 2 queries , intersection in programming language of choice.
select subject, pid photo_tag subject = me()
select pid, subject photo_tag subject in (select uid2 friend uid1=me())
batch these 2 calls
fql?q={"userphotos":"select subject, pid photo_tag subject = me()", "friendphotos":"select pid, subject photo_tag subject in (select uid2 friend uid1=me())"}
then in programming language intersection of these 2 sets.
a0 = data['data'][0]['fql_result_set']
a1 = data['data'][1]['fql_result_set']
for example in python, simple as
>>> photos = {} >>> p in a0: ... 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'])
photos give dict each key having list of ids value. take 10 of these , supply photo
table fql call
in python facepy
module might like
photoquery = 'select pid, src_big photo '+ 'pid ='+pid1+' or 'pid ='+pid2+' or ... graph.fql(photoquery)
the slowest section overall photo_tag query on friends. select pid, subject photo_tag subject in (select uid2 friend uid1=me())
Comments
Post a Comment