Skip to content

Instantly share code, notes, and snippets.

@micmmakarov
Created November 11, 2015 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micmmakarov/c7733145cc3840deca9c to your computer and use it in GitHub Desktop.
Save micmmakarov/c7733145cc3840deca9c to your computer and use it in GitHub Desktop.
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