Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Analyze person's likes to figure out who's the most active
api_key = "https://developers.facebook.com/tools/explorer"
api = Koala::Facebook::API.new(api_key)
profile = api.get_object("me")
profile = _
profile.keys
profile['birthday']
feed = api.get_connections "me", "feed"
likes = feed.map do |f|
if f['likes']
f['likes']['data'].map {|like| like['name']}
end
end.flatten
stats = {}
likes.each do |name|
if stats[name]
stats[name] += 1
else
stats[name] = 1
end
end
likes_array = stats.map {|key, value| {name: key, likes: value}}
likes_array.sort! {|a, b| b[:likes] <=> a[:likes]}
likes_array.each do |like|
puts "#{like[:name]}: #{like[:likes]}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment