Question

As the subject says, I am trying to get the most recent comments from a Facebook page, with associated user data. I am using Open Graph & the PHP SDK.

This works fine for the posts:

$fql_query = "
    SELECT fromid, id, post_id, time, text  
    FROM comment  
    WHERE post_id IN (SELECT post_id FROM stream WHERE source_id = '" . $fb_id . "') 
    ORDER BY time DESC LIMIT 1000";

$feed = $facebook->api(array(
    'method' => 'fql.query',
    'query' => $fql_query
    ));

And this is how to get the user details I need:

$fql_query = "
    SELECT pic_square, name  
    FROM user 
    WHERE uid = '" . $user_id . "'
    ";

And, according to everything I can find, this should combine the two using fql.multiquery:

$fql_queries = "{
    \"query1\" : \"
    SELECT fromid, id, post_id, time, text 
    FROM comment 
    WHERE post_id IN (SELECT post_id FROM stream WHERE source_id = '" . $fb_id . "') 
    ORDER BY time DESC LIMIT 1000
    \", 
    \"query2\" : \"SELECT pic_square, name FROM user WHERE uid IN (SELECT fromid FROM #query1)\"
    }";

$feed = $facebook->api(array(
    'method' => 'fql.multiquery',
    'queries' => $fql_queries
    ));

But it just returns an empty array. Does anyone know where I'm going wrong or have a better method to do what I require? TIA, as always.

Was it helpful?

Solution

I tested this in the Graph API explorer on one of my pages and it works fine.

Does this multiquery work on your page in the Graph API explorer? If yes, then it's a permissions issue.

Perhaps your issue is in the way you're hard-coding the json. I use syntax like this on my site. (It's more readable too):

$fql_queries = array(
   'query1' => "SELECT fromid, id, post_id, time, text...",
   'query2' => "SELECT pic_square, name FROM user..."
);

...
    'queries' => json_encode($fql_queries)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top