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:
If you're working with PHP and need a single array of comments to loop through this function might come in handy:
Returns a single array of comments with the commentID as key: