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 dat开发者_运维知识库e you can see at the top of the friendship page ("Facebook friends since...").
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
This date isn't available via the Graph API or FQL tables. You can log a feature request with Facebook or get creative with workarounds such as those you linked in the post.
精彩评论