在 FQL 中查找 10 个随机 Facebook 好友的照片?
我正在尝试执行 Facebook FQL Multiquery(通过 JS SDK FB.api 调用)为已标记的 10 个随机 Facebook 好友中的每一个加载一张照片(又名“显示 10 个随机好友和他们的照片”) 。这是我的 Javascript 查询数组:
var queries = {
q1:"SELECT uid, name FROM user WHERE uid IN (Select uid2 from friend where uid1 = " + user_id
+ " order by rand() limit 10) ",
q2: "SELECT pid, subject from photo_tag where subject in (SELECT uid from #q1) limit 10",
q3:"SELECT src from photo where pid in (SELECT pid from #q2)"};
我想要做的事情:
- 查询 1:获取用户 10 个随机朋友的用户 ID 和姓名。
- 查询 2:获取用户 ID 与查询 1 中的用户 ID 相匹配的照片标签的照片 ID 和主题名称。
- 查询 3:从与查询 2 中的照片相匹配的照片中选择图像 src。
问题是我在查询 2 中没有办法由用户选择不同的记录。也就是说,我不能告诉 Facebook 只为每个用户返回一张照片。现在,它是任意的,所有 10 行都可以是同一用户的不同照片标签。
我可以在 Javascript 中进行一些循环,并对每个匹配用户的图片进行单个 FQL 查询,但这似乎是错误的。关于如何有效地执行此操作(最好直接在 FQL 中)还有其他建议吗?
谢谢!
I'm attempting to do a Facebook FQL Multiquery (via JS SDK FB.api call) to load a single photo for each of 10 random Facebook friends where they have been tagged (aka "Show 10 random friends and a photo of theirs"). Here is my Javascript array of queries:
var queries = {
q1:"SELECT uid, name FROM user WHERE uid IN (Select uid2 from friend where uid1 = " + user_id
+ " order by rand() limit 10) ",
q2: "SELECT pid, subject from photo_tag where subject in (SELECT uid from #q1) limit 10",
q3:"SELECT src from photo where pid in (SELECT pid from #q2)"};
What I was trying to do:
- Query 1: Get the userid and name of 10 random friends of the user.
- Query 2: Get the photo id and subject name of phototags where the user ids matched those from query 1.
- Query 3: Select the image src from the photos that matched those in query 2.
The problem is that I have no way in Query 2 to select DISTINCT records by users. That is, I cannot tell Facebook to return just a single photo for each user. Right now, it is arbitrary and all 10 rows could be different photo tags of the same user.
I could do some looping in Javascript and make a single FQL query for a pic for each matched user, but that just seems wrong. Any other suggestions on how to do this efficiently, preferably directly in FQL?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我不久前解决了这个问题,为了完整起见,我将关闭它。
我要做的不是在单个多查询中完成所有操作。我必须首先进行一个查询来检索一些随机的朋友,然后进行一个多重查询,为每个朋友加载一张随机照片。
Well, I solved this awhile back and am closing this for completeness.
What I had to do was NOT do it all in a single multiquery. I had to FIRST make a single query to retrieve some random friends, THEN make a multiquery where we load a random photo for each of these friends.