1

I'm trying to find the best way to query both news feed and wall using a single request.

First attempt:

  • Query me/home and me/feed in batch request.
  • Problem: querying me/home gives me bad results due to Graph API bugs (showing blocked items and on the contrary not showing some items that should be shown) so I decided to change to FQL which seems to handle it much better.

Second attempt:

  • Use single batch request to query: (1) me/feed directly. (2) fql.query for stream table with filter_key set to 'others'.
  • Problem: Needs to also query for user names because the stream table contains only ids.

Third attempt:

  • Use batch request to query: (1) me/feed directly (2) fql.multiquery for stream table with filter_key set to 'others' and the names table with "WHERE id IN (SELECT actor_id FROM #stream)".
  • Problem: Fails. It returns "Error: batch parameter must be a JSON array" although it is a json array.

Fourth Attempt:

  • Use fql.multiquery to get news feed stream, wall stream and names.
  • Problem: I have no idea how to get a view similar to me/feed using FQL. The best I could get is a list of all my own posts but it doesn't show photos the user is tagged in (so I guess more things are missing).

Appreciate any hints.

roee88
  • 195
  • 2
  • 12
  • It would be helpful to understand the complete requirements. Your question states that you want to get both newsfeed and wall using a single request, then later on you say you don't get the user's name (which is not part of the stream table). So I'm confused, do you want names, or do you want the stream items? – DMCS Jan 30 '12 at 00:43
  • The final task is showing a human readable list of items for each view (newsfeed and wall). If you query for me/home or me/feed you will get the name of the users for each post. The FQL query only return ids so a separate query for names is needed (only to map between id and name on posts). – roee88 Jan 30 '12 at 18:50

1 Answers1

1

Due to FQL not doing SQL style joins, getting information from multiple tables in one query is currently impossible.

  1. Use FQL on the stream table to get the list of posts you want to display be sure to grab the source_id. The source_id can be a user id, page id, event id, group id, and there may be more objects too, just don't remember off the top of my head. (You may also want to do similar caching of the actor_id, target_id and viewer_id)
  2. Cache the source_ids in a dictionary style data cache with source_id being the PK.
  3. Loop thru the cache for ones you don't have information on
  4. Try grabbing the information from the user table based upon id, then next the page table, then event table, and group table until you can find what that ID belongs to. Store the information in your cache
  5. For display merge together the stream table items with the source_id information.
DMCS
  • 31,720
  • 14
  • 71
  • 104
  • Many thanks for the answer but fql multiquery does allow getting information from multiple tables at once. Reference: http://developers.facebook.com/docs/reference/rest/fql.multiquery/ I have no problem querying the stream table and the profile table in a single fql.multiquery. My only problem is to get the wall items (me/feed) in the same call. If it is possible to get the wall using FQL how would like to know how, otherwise I would like to know how to combine fql.multiquery and standard query in a batch request (combining fql.query and standard query in batch works fine). – roee88 Jan 30 '12 at 23:10
  • Isn't that what I said? "*getting information from multiple tables in one query is currently impossible.*" So how are you doing it? please post your one query that joins information from multiple tables. I'm not talking about mutli-query where there's independent result groupings that need to be post-parsed to join. Please show me your query that accomplishes that, I'm very willing to learn. – DMCS Jan 30 '12 at 23:16
  • I never said there is no need for post parsing (this was never needed in my question) but it's still one query for both stream items and related names. Example: { "stream": "SELECT post_id, actor_id FROM stream where filter_key='others' ORDER BY created_time DESC", "names": "SELECT id, name FROM profile where id IN (SELECT actor_id FROM #stream)" } – roee88 Feb 04 '12 at 18:48
  • Yep, just checking, that's what I stated. Impossible without post processing. :) Thanks for the clarification. – DMCS Feb 04 '12 at 20:28