我一直在寻找一种方法来了解两个用户成为朋友的日期。我找到了这个问题,但它只解释了如何使用多个 FQL 查询来模拟友谊页面。
我要确定的是您可以在友谊页面顶部看到的日期(“Facebook 朋友自从...”)。
我一直在寻找一种方法来了解两个用户成为朋友的日期。我找到了这个问题,但它只解释了如何使用多个 FQL 查询来模拟友谊页面。
我要确定的是您可以在友谊页面顶部看到的日期(“Facebook 朋友自从...”)。
我以一种无可否认的方式做到了这一点。您可以使用帖子端点获取所有帖子,然后选择包含“现在朋友”字样的帖子。该story_tags
字段将包含一个描述朋友详细信息的对象。在 Rails 中,您可以使用facebook gem来执行此操作:
# 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
哪个输出:
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.