Search code examples
rubyfacebookomniauthkoala

Gathering a user's news feed with Koala (Ruby)


I want to pull in a user's newsfeed after they have authenticated. I am using the Koala gem but if I call get_connection('me', 'feed') it only returns the last three posts on my wall. I want the last ~100 posts (or since post 1234567) that would show up on the user's home page.


Solution

  • You can get all posts during a certain time period using FQL. Here is an example that should get you started:

    @feed = Koala::Facebook::API.new(current_user.token)
    to = Time.now.to_i
    yest = 1.day.ago.to_i
    @feed.fql_query("SELECT post_id, actor_id, target_id, message, likes FROM stream WHERE source_id = me() AND created_time > #{yest} AND created_time < #{to} AND type = 80 
    AND strpos(attachment.href, "youtu") >= 0")
    
    require 'koala'
    @graph = Koala::Facebook::API.new("YOUR_ACCESS_TOKEN")
    @graph.fql_query("SELECT post_id, actor_id, target_id, message FROM stream WHERE source_id = me() AND created_time > START_TIME AND created_time < END_TIME LIMIT 10")
    

    Code borrowed from here.