我正在尝试使用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)"};
我想做的事情:
问题是我在查询2中无法用户选择DISTINCT记录。也就是说,我无法告诉Facebook为每个用户返回一张照片。现在,它是任意的,所有10行可能是同一用户的不同照片标签。
我可以在Javascript中进行一些循环,并为每个匹配的用户为pic进行单个FQL查询,但这似乎是错误的。关于如何有效地执行此操作的任何其他建议,最好直接在FQL中进行?
谢谢!
答案 0 :(得分:2)
好吧,我已经解决了一段时间,并且为了完整性而关闭了它。
我必须做的就是不要在一个多个查询中完成所有操作。我不得不首先做一个查询来检索一些随机的朋友,然后做一个多重查询,我们为这些朋友加载一张随机照片。
FB.api(
{
method: 'fql.query',
query: "SELECT uid, name FROM user WHERE uid IN (Select uid2 from friend where uid1 = " + user_id
+ " order by rand() limit 8) "
}, function (response) {
var queries = {};
for (x in response) {
if (typeof photoArray[response[x].uid] == 'undefined') photoArray[response[x].uid] = [];
photoArray[response[x].uid]['name'] = response[x].name;
queries[response[x].uid] = "SELECT src_big, caption from photo where pid in (SELECT pid from photo_tag where subject =" + response[x].uid + " order by rand() limit 1) ";
}
FB.api(
{
method: 'fql.multiquery',
queries: queries
},
function(response) {
for (y in response) {
if (typeof response[y].fql_result_set[0] != 'undefined') {
photoArray[response[y].name]['image_src'] = response[y].fql_result_set[0].src_big;
// Do what you want with the pics
}
}