d4rklit3
d4rklit3

Reputation: 427

Facebook FQL returning duplicate posts in query

I am trying to get the last 10 posts from a user's stream. For some reason my FQL query will return two of every post in succession. Here is my code, Pardon the CoffeeScript,

method = 'fql.multiquery'
queries = 'feed' : "SELECT attachment , type , created_time , filter_key,     actor_id, description, message  FROM stream WHERE (filter_key = 'others' OR filter_key = 'owner') ORDER BY created_time DESC LIMIT 10"
params =
    method : method
    queries : queries
FB.api (params) , (response) =>
    #and so on

I am not really sure why this is happening.

Upvotes: 1

Views: 559

Answers (1)

Anna Billstrom
Anna Billstrom

Reputation: 2492

FQL can't do group by's, and Facebook stores post stories in various ways, so there are "multiples". The way to get around this is to select the columns you need, and do a "where in" to limit your result set, i.e.:

select 
    attachment , type , created_time , filter_key, actor_id, description, message
FROM 
   stream
WHERE 
   post_id in (select post_id 
      FROM 
         stream 
     WHERE 
          (filter_key = 'others' OR filter_key = 'owner' and created_time < [long-ass unix time])
  )
  • don't believe you can do limits, you should do less than/greater than a date, or parse and sort result set

Upvotes: 2

Related Questions