Juuso Kosonen
Juuso Kosonen

Reputation: 216

How to get FQL Stream with full names

I would like to show stream data from FQL

fql?q=SELECT post_id, app_id, source_id, updated_time, created_time, filter_key,
      attribution, actor_id, target_id, message, app_data, action_links, 
      attachment, impressions, comments, likes, place, privacy, permalink, xid,
      tagged_ids, message_tags, description, description_tags, type 
      FROM stream WHERE filter_key in (
            SELECT filter_key FROM stream_filter WHERE uid=me() 
            AND type='newsfeed')

but the problem is that that table doesn't have name of the users/pages, only ids.

Is there any way to get names to those results too? And not only actor_id, but also name for the people who has made comments.

Do I need to make multiquery and search against all those ids in the stream, and then fetch from user and page tables. And then loop those results for every single stream result, seems kind of heavy. Any easier way?

Upvotes: 1

Views: 1687

Answers (2)

Gaurav Taywade
Gaurav Taywade

Reputation: 8347

You can do it in following way :

 NSString *query =
    @"{"
    @"'friends':'SELECT post_id,actor_id,target_id,message,created_time, likes, comment_info FROM stream WHERE source_id IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND created_time > 1  ORDER BY created_time DESC LIMIT 50',"
    @"'friendinfo':'SELECT uid, name, pic_square FROM user WHERE uid IN (SELECT actor_id FROM #friends)',"
    @"}";

Once you will get result, store it into two arrays like this :

FBFriendsNewsArray =(NSArray *) [[[result objectForKey:@"data"]objectAtIndex:0]objectForKey:@"fql_result_set"];

                              FBFriendsInfoArray=(NSArray *) [[[result objectForKey:@"data"]objectAtIndex:1]objectForKey:@"fql_result_set"];

And while displaying Feed search for that user id (actor_id) in Friends info array. hope this will help.

Upvotes: 1

Neil
Neil

Reputation: 1066

I'm not sure if there is a way to get all the users and pages in one go but you could run two separate queries that will return the users/pages and then performance an array merge with both sets of results.

Users

SELECT uid,name from user where uid in (SELECT source_id FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid=me() AND type='newsfeed'))

Pages

SELECT page_id,name from page where page_id in (SELECT source_id FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid=me() AND type='newsfeed'))

Upvotes: 3

Related Questions