From the below FQL query I’m able to get the actor_id and attachment data for a post that is on my newsfeed and contains ‘www.youtube.com’. However, I’d like to be able to also get that user’s picture and name. How would I incorporate this into the below query?
SELECT created_time, post_id, actor_id, type, updated_time, attachment
FROM stream
WHERE post_id IN
(SELECT post_id
FROM stream
WHERE ('video') IN attachment
AND source_id IN
(SELECT uid2
FROM friend
WHERE uid1=me())
LIMIT 100)
Edit:
#right fql query, but prints only part of it
posts_query = "SELECT created_time, post_id, actor_id, type, updated_time, attachment FROM stream WHERE post_id in (select post_id from stream where ('video') in attachment AND source_id IN ( SELECT uid2 FROM friend WHERE uid1=me()) limit 100)"
fql_var = "https://api.facebook.com/method/fql.query?access_token=" + token['access_token'] + "&query=" + posts_query + "&format=json"
data = urllib.urlopen(fql_var)
fb_stream = json.loads(data.read())
#print ast.literal_eval(json.dumps(fb_stream))
users_query = "SELECT uid, first_name FROM user WHERE uid IN (SELECT actor_id FROM (" + posts_query+"))"
fqlquery_user = "https://api.facebook.com/method/fql.query?access_token=" + token['access_token'] + "&query=" + users_query + "&format=json"
user_data2 = urllib.urlopen(fqlquery_user)
user_stream2 = json.loads(user_data2.read())
print ast.literal_eval(json.dumps(user_stream2))
It seems you can’t do it with only one query, because:
SELECTfrom one table at once in FQL.If you could, this is how it would look like:
But there are no joins, so you need to use what Facebook calls a multiquery, and you would have two queries:
Here is a link to the Explorer for you to test it.
Note: There is something useless you are doing in your original query, which is selecting from a table, and adding a subquery in the where clause from that same table. So that’s redundant.
Update:
The idea is to send both queries with their names as keys, encode in JSON, so that Facebook understands that
#posts_queryis the one you sent in that same API request. You to send the name exactly as you send it in the JSON encoded object literally, not replace it by the query itself. Check the docs on multiquery for details and examples.