I want to a build a website that show the user all videos that his friends published on facebook, I know how to pull the news feed for recent posts, but I don't know how to pull all the posts for specific day (all the posts from the start of the day).
I use this FQL call to pull the recent videos:
SELECT post_id, source_id, actor_id, target_id, message, attachment, permalink, type FROM stream
WHERE source_id IN (SELECT target_id FROM connection WHERE source_id=me() AND is_following=1)
AND is_hidden = 0
AND type = 80
AND strpos(attachment.href, "youtu") >= 0
but I don't know how to pull all the videos from the start of the day to it's ending...
Edit:
Now I have in my code as your answer:
@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")
and the feed variable returns me # and not a json, how can I get a json from this variable?
Using FQL is probably your best bet. You will need the read_stream permission from the user.
You can use the Koala gem and run the following:
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")
Both START_TIME and END_TIME should be unix timestamps. In your case, representing the start and end of the day.
to_i method of the time class. (Time.now.to_i) Also http://stackoverflow.com/questions/1805950/ruby-rails-converting-a-date-to-a-unix-timestam - Gazler 2012-04-04 20:03
sort_by {|l| l["likes"]["count"].to_i } on your dataset should work. http://developers.facebook.com/docs/reference/fql/stream/
- Gazler 2012-04-04 20:21
to_json on it - Gazler 2012-04-04 20:33