views:

793

answers:

2

Hello,

I am trying to write a Facebook query that will return all comments posted by a user to his friends,

however I can't seem to find the correct schema. Its as if there are no 'indexable' fields to build this.

Any suggestions please?

With thanks,

Wineshtain

A: 

I don't believe you can accomplish this in a direct manner as you describe. FQL tables are generally only indexed on a limited criteria (for performance reasons I'm sure). In the case of the Comments FQL Table, you can only select comments via a post ID or an xid.

Unfortunately, this means that you have to know the objects that a user has commented on before you can get the comments for it. You would have to have previously selected all the posts, photos, etc. that you wished to get the comments for before you could retrieve them.

zombat
Thanks for replying!Any tips on how to do this indirectly? How to gather those posts/photos?
Ws
I'm not sure if there is a way or not. I've never done anything like that myself, so I'd probably start by reading over the API docs and FQL tables for other objects (posts, photos, etc) and seeing how they are indexed and what it would take to get some of them.
zombat
A: 

The indirect path for stream comments would be something like

select * from comments where fromid = <my_id> and object_id in (
   select post_id from stream where sourceid in (
       select uid1 from friend where uid2 = <my_id> ) )

for photos, substitute the middle query with

SELECT pid FROM photo WHERE aid IN ( SELECT aid FROM album WHERE owner IN ( ...

Unfortunately the security settings may restrict the querying your friends wall posts and photos.

Stevko
The problem I encountered using this method is the limit on number of results returned. Since we are getting the friends list and their posts that easly gets to the limit on results to return before even "reaching" to the posts where <my_id> actually commented on anything. so the returned result is always 0. (well 99% of the times zero unless your user comments on everything or just the latest posts). Anyway to resolve this?
Ws
Your goal of "all comments posted by user" is impossible due to the stream getting truncated based on some non-published criteria (date? size? activity?). The data is just not there.In order to get past the results limitation, you need to narrow the scope of your search and perform multiple queries.I suggest caching the friends ids and walking it N ids at a time.I also suggest limiting the posts returned -1) actor_id=<fiend id> (post created by friend)2) created_time > lastweek (most recent posts)3) using a LIMIT to prevent overflowLastly, you may want to investigate the multiquery
Stevko
Thanks!!!!Great suggestions!
Ws

related questions