如何使用FB FQL多重查询的结果? [英] How do I use the result from FB FQL multiquery?

查看:118
本文介绍了如何使用FB FQL多重查询的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Facebook的fql.multiquery方法感到困惑。



我正在检索一个帖子上的所有评论,然后每个用户的信息以及。我可以得到评论没有任何问题,但我无法获取用户。



目前我使用以下:

  FB.api({
method:'fql.multiquery',
queries:{
query1:'SELECT post_fbid, fromid,text,time FROM comment WHERE post_id ='+ postID +''
query2:'SELECT id,name,url,pic FROM profile WHERE id IN(SELECT fromid FROM#query1)'
}
},
函数(响应){
}
})

这给我以下回应:

  [
{
name :query1,
fql_result_set:[
{
post_fbid:xxxxx,
fromid:user1id,
text $ a


$ bpost_fbid:xxxxx,
fromid:user2id,
text:另一个评论,
time:1308580031
}
]
},
{
name:query2,
fql_result_set:[
{
id:user1id,
name:User 1 name,
url:User 1 url,
pic:User 1 pic
},
{
id:user2id,
name:User 2 name,
url:User 2 url,
pic:User 2 pic
}
]
}
]

问题是,我不知道如何匹配这些!所以我循环了评论,并希望打印每个人的文本旁边的用户的名字。或者,有没有更好的方法呢?

解决方案

您可以通过循环访问注释并将fromid与用户响应中的id进行匹配来匹配这些结果。



例如: p>

  var comments = response [0] .fql_result_set; 
var users = response [1] .fql_result_set;

//循环通过评论
for(var i = 0,j = comments.length; i< j; i ++){

for(var x = 0,y = users.length; x< y; x ++){
if(comments [i] .fromid == users [x] .id){
//我们有一个匹配,评论来自用户用户[x]
//进程用户[x]
//打破内部循环,因为我们已经有一个匹配
}
}

}


I'm confused by Facebook's fql.multiquery method.

I'm trying to retrieve all the comments on a post, and then the user information for each one as well. I can get the comments without any problem, but I'm having trouble getting the users.

Currently I'm using the following:

  FB.api({
   method: 'fql.multiquery',
   queries: {
    query1: 'SELECT post_fbid, fromid, text, time FROM comment WHERE post_id="'+postID +'"',
    query2: 'SELECT id, name, url, pic FROM profile WHERE id IN (SELECT fromid FROM #query1)'
   }
  },
  function(response) {
  }
})

This gives me the following response:

[
  {
    "name": "query1",
    "fql_result_set": [
      {
        "post_fbid": "xxxxx",
        "fromid": user1id,
        "text": "Here's a comment",
        "time": 1308579931
      },
      {
        "post_fbid": "xxxxx",
        "fromid": user2id,
        "text": "Another comment",
        "time": 1308580031
      }
    ]
  },
  {
    "name": "query2",
    "fql_result_set": [
      {
        "id": user1id,
        "name": "User 1 name",
        "url": "User 1 url",
        "pic": "User 1 pic"
      },
      {
        "id": user2id,
        "name": "User 2 name",
        "url": "User 2 url",
        "pic": "User 2 pic"
      }
    ]
  }
]

Problem is, I don't know how to match these up! So I'm looping over the comments, and want to print the text of each one with the user's name next to it. How do I do that?

Or, is there a better way to do this?

解决方案

You could match these results up by looping over the comments and matching the fromid to an id from the users response.

For example:

    var comments = response[0].fql_result_set;
    var users = response[1].fql_result_set;    

    //loop through the comments
    for(var i = 0, j = comments.length; i<j; i++){

        for(var x = 0, y = users.length; x<y; x++){
             if(comments[i].fromid == users[x].id){
                 //we have a match, this comment is from user users[x]
                 //process users[x]
                 //break the inner for loop, since we already have a match
             }
        }

    }

这篇关于如何使用FB FQL多重查询的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆