Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get friendship start date

I've been looking for a way to know the date two users became friends. I've found this question but it only explains how to simulate the friendship page with multiple FQL queries.

What I want to determine is the date you can see at the top of the friendship page ("Facebook friends since...").

like image 267
jocriaba Avatar asked Dec 28 '22 14:12

jocriaba


1 Answers

I've done this in a way which is admittedly a bit hackish. You can use the posts endpoint to get all posts, then select the posts that contain the words "now friends". The story_tags field will contain an object describing the details of the friend. In rails, you can use the facebook gem to do this:

# To retrieve your friendship start dates
user = {fb_id: <your fb id>, auth_token: <your fb auth token>}
fb_user = FbGraph::User.me(user[:auth_token])
posts = fb_user.posts(:since => 10.days.ago.to_i, :until => Time.now.to_i)
posts = posts.reject{|p| p.story.nil? || (!p.story.include?("now friends"))}
posts.each do |p|
  p.story_tags.each do |t|
    unless t.identifier == user[:fb_id]
      puts "You became friends with #{t.name} at #{p.created_time}"
    end
  end
end

Which outputs:

You became friends with Christina Ricci at 2013-01-12 20:34:58 UTC
You became friends with Michael Jordon at 2013-01-09 19:51:51 UTC
You became friends with Barack Obama at 2013-01-04 19:06:51 UTC
like image 141
Kevin Cantwell Avatar answered Apr 28 '23 08:04

Kevin Cantwell