user2994739
user2994739

Reputation: 33

Multi query in FQL that isn't pulling data correctly

I am not sure as to why my request isn't pulling correctly the data I'm seeking. I am new to FQL and not sure how to exactly incorporate the WHERE IN in this format. I'm trying to avoid using a facebook object.

The purpose of my query is to get the facebook user_ids of those who have liked on the last 100 posts.

$fql_multiquery_url = 'https://graph.facebook.com/fql?q='
. '"post+ID":"SELECT+post_id+FROM+stream+WHERE+source_id=6979393237+LIMIT+100",'
. '"like+ID":"SELECT+user_id+FROM+like+WHERE+post_id+IN+#postID"}'
. '&access_token=' . $access_token;

Upvotes: 1

Views: 97

Answers (2)

Tobi
Tobi

Reputation: 31479

Why not the following:

$fql_query_url = 'https://graph.facebook.com/fql?q=SELECT+user_id+FROM+like+WHERE+post_id+IN+(SELECT+post_id+FROM+stream+WHERE+source_id=6979393237)+LIMIT+100&access_token=' . $access_token;

I don't see the need for two separate queries if you can use query nesting (for a reference look here: https://developers.facebook.com/docs/technical-guides/fql/#query)

Upvotes: 0

Stéphane Bruckert
Stéphane Bruckert

Reputation: 22903

Your FQL multi-query looks senseful, but why doesn't it work?

  1. Don't use spaces inside your query names.
  2. #this is not a variable (but a complete result set containing several rows), so you need to write an additional query (using SELECT) to get the interesting row (say post_id).
  3. You forgot the opening curly bracket in your FQL query {.

FQL query:

{
 "posts":"SELECT post_id FROM stream WHERE source_id=6979393237 LIMIT 100",
 "likes":"SELECT user_id FROM like   WHERE post_id IN (SELECT post_id FROM #posts)"
}

Test it.

PHP code:

$fql_multiquery_url = 'https://graph.facebook.com/fql?q={'
. '"posts":"SELECT+post_id+FROM+stream+WHERE+source_id=6979393237+LIMIT+100",'
. '"likes":"SELECT+user_id+FROM+like+WHERE+post_id+IN+(SELECT+post_id+FROM+#posts)"}'
. '&access_token=' . $access_token;

Upvotes: 1

Related Questions