Created
July 4, 2013 19:45
-
-
Save manewitz/5929858 to your computer and use it in GitHub Desktop.
Playing with the Facebook API. This is aggregates music 'Likes' from your Facebook Friends list. Visit https://developers.facebook.com/tools/explorer, click "Get Access Token", and assign appropriate permissions to get your token, assigning it to the FACEBOOK_GRAPH_ACCESS_TOKEN constant.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Aggregated music 'Likes' from my Facebook Friends list | |
require 'koala' | |
# Visit https://developers.facebook.com/tools/explorer | |
# and click "Get Access Token", assigning appropriate permissions | |
@graph = Koala::Facebook::API.new(FACEBOOK_GRAPH_ACCESS_TOKEN) | |
def q(query) | |
@graph.fql_query query | |
end | |
def sorted_counts_from_list(list) | |
counts = list.each_with_object(Hash.new(0)){|a, h| h[a] += 1 } | |
sorted = counts.sort_by{|k, v| v}.reverse | |
end | |
def user_music | |
q("SELECT music FROM user WHERE uid IN (#{@ids.join', '})") | |
.reject{|u| u["music"].empty? } | |
.map{|u| u["music"] } | |
.flatten | |
.join(", ") | |
.split(", ") | |
end | |
def page_likes | |
q( | |
"SELECT name | |
FROM page | |
WHERE page_id | |
IN( | |
SELECT page_id | |
FROM page_fan | |
WHERE uid IN (#{@ids.join', '}) AND profile_section='music' | |
) | |
AND type='MUSICIAN/BAND'" | |
).map{|p| p["name"] } | |
end | |
friends = @graph.get_connections("me", "friends") | |
@ids = friends.map{|u| u["id"] } | |
# search Music Likes AND Musician Page Likes: | |
list = user_music + page_likes | |
final_count = sorted_counts_from_list(list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# These are all the artists that 5 or more of my Facebook friends "Like" - Mike | |
{ | |
"Radiohead" => 29, | |
"TX" => 28, | |
"Pink Floyd" => 27, | |
"Johnny Cash" => 25, | |
"The Beatles" => 23, | |
"Bob Marley" => 22, | |
"Mumford and Sons" => 19, | |
"Austin City Limits Music Festival (ACL)" => 19, | |
"Tom Waits" => 17, | |
"The Black Keys" => 15, | |
"Michael Jackson" => 15, | |
"Bob Dylan" => 15, | |
"David Bowie (Official)" => 14, | |
"Bon Iver" => 14, | |
"Tool" => 14, | |
"The Cure" => 13, | |
"Willie Nelson" => 13, | |
"Wilco" => 12, | |
"Daft Punk" => 12, | |
"Arcade Fire" => 12, | |
"Sublime" => 12, | |
"Lady Gaga" => 12, | |
"deadmau5" => 12, | |
"Lil Wayne" => 11, | |
"Led Zeppelin Official" => 11, | |
"Miles Davis" => 11, | |
"RUSH" => 11, | |
"Muse" => 11, | |
"Bright Eyes" => 11, | |
"Dave Matthews Band" => 11, | |
"Beastie Boys" => 11, | |
"Björk" => 10, | |
"Mixed Use Media" => 10, | |
"C3 Concerts" => 10, | |
"The Raconteurs" => 10, | |
"J Dilla" => 10, | |
"Depeche Mode" => 10, | |
"MGMT" => 10, | |
"Minor Mishap Marching Band" => 9, | |
"M83" => 9, | |
"The Clash" => 9, | |
"Iron & Wine" => 9, | |
"Beck" => 9, | |
"The National" => 9, | |
"The Doors" => 9, | |
"Fleet Foxes" => 9, | |
"Otis Redding" => 9, | |
"Adele" => 9, | |
"Pretty Lights" => 9, | |
"Metallica" => 9, | |
"Merle Haggard" => 9, | |
"Modest Mouse" => 9, | |
"Girl Talk" => 9, | |
"AC/DC" => 9, | |
"Stevie Ray Vaughan" => 9, | |
"Kings Of Leon" => 9, | |
"Queen" => 9, | |
"The Avett Brothers" => 9, | |
"New Order" => 9, | |
"Mike Patton" => 8, | |
"Led Zeppelin" => 8, | |
"Stubb's Austin" => 8, | |
"The Kinks" => 8, | |
"Beirut" => 8, | |
"Pantera" => 8, | |
"Elton John" => 8, | |
"Edward Sharpe and the Magnetic Zeros" => 8, | |
"Massive Attack" => 8, | |
"AUSTIN PSYCH FEST" => 8, | |
"Atmosphere" => 8, | |
"Sigur Rós" => 7, | |
"Snoop Dogg" => 7, | |
"The Smiths" => 7, | |
"Mother Falcon" => 7, | |
"U2" => 7, | |
"Faith No More" => 7, | |
"The Killers" => 7, | |
"Jack Johnson" => 7, | |
"Justice" => 7, | |
"The Black Angels" => 7, | |
"Gorillaz" => 7, | |
"MF Doom" => 7, | |
"The White Stripes" => 7, | |
"Grateful Dead" => 7, | |
"Vampire Weekend" => 7, | |
"The Decemberists" => 7, | |
"Joy Division" => 7, | |
"The Shins" => 7, | |
"Neil Young" => 7, | |
"Queens of the Stone Age" => 7, | |
"Neon Indian" => 7, | |
"Fun Fun Fun Fest" => 7, | |
"Aesop Rock" => 7, | |
"Jeff Buckley" => 7, | |
"Explosions in the Sky" => 7, | |
"Skrillex" => 7, | |
"Ghostland Observatory" => 7, | |
"What Made Milwaukee Famous" => 7, | |
"Panjoma" => 7, | |
"PIXIES" => 7, | |
"My Morning Jacket" => 7, | |
"Red Hot Chili Peppers" => 7, | |
"Dubstep" => 7, | |
"Death Cab for Cutie" => 7, | |
"Tori Amos" => 7, | |
"The Civil Wars" => 7, | |
"Rilo Kiley" => 7, | |
"Flying Lotus" => 6, | |
"De La Soul" => 6, | |
"dubstep" => 6, | |
"Bassnectar" => 6, | |
"Ray Lamontagne" => 6, | |
"STS9" => 6, | |
"Iron Maiden" => 6, | |
"Al Green" => 6, | |
"Alicia Keys" => 6, | |
"STEREO IS A LIE" => 6, | |
"Aphex Twin" => 6, | |
"Boards Of Canada" => 6, | |
"Portugal. The Man" => 6, | |
"Sarah Jaffe" => 6, | |
"Frank Sinatra" => 6, | |
"Janis Joplin" => 6, | |
"Beats Antique" => 6, | |
"Regina Spektor" => 6, | |
"Wye Oak" => 6, | |
"Coldplay" => 6, | |
"Bruce Springsteen" => 6, | |
"Sade" => 6, | |
"Santigold" => 6, | |
"Rihanna" => 6, | |
"Them Crooked Vultures" => 6, | |
"Black Sabbath" => 6, | |
"Nine Inch Nails" => 6, | |
"Misfits" => 6, | |
"Technicolor Hearts" => 6, | |
"Punksoda" => 6, | |
"The Pons" => 6, | |
"Quiet Company" => 6, | |
"The Mohawk Austin" => 6, | |
"The Sour Notes" => 6, | |
"Soul Track Mind" => 6, | |
"Counting Crows" => 6, | |
"ELVIS PRESLEY" => 6, | |
"Furthur" => 6, | |
"The Strokes" => 6, | |
"Les RAV" => 6, | |
"Mr. Bungle" => 6, | |
"Foot Patrol" => 6, | |
"Phoenix" => 6, | |
"The Knife" => 6, | |
"Nick Drake" => 6, | |
"Golden Hornet Project" => 6, | |
"DJ Shadow" => 6, | |
"A Tribe Called Quest" => 6, | |
"Wu-Tang" => 6, | |
"Mos Def Official" => 6, | |
"Madlib" => 6, | |
"Band of Horses" => 6, | |
"Wu-Tang Clan" => 6, | |
"Aaron Ivey" => 6, | |
"Eminem" => 6, | |
"Waylon Jennings" => 6, | |
"Neko Case" => 6, | |
"The Octopus Project" => 6, | |
"Herbie Hancock" => 5, | |
"The Glitch Mob" => 5, | |
"aphex.twin" => 5, | |
"Metric" => 5, | |
"Phantogram" => 5, | |
"Agent Ribbons" => 5, | |
"Diplo" => 5, | |
"Built to Spill" => 5, | |
"Spiritualized" => 5, | |
"Jurassic 5" => 5, | |
"City and Colour" => 5, | |
"Sleigh Bells" => 5, | |
"Rusko" => 5, | |
"Okkervil River" => 5, | |
"James Brown" => 5, | |
"DJ CHICKEN GEORGE" => 5, | |
"Leonard Cohen" => 5, | |
"The Faint" => 5, | |
"Elliott Smith" => 5, | |
"The Temper Trap" => 5, | |
"Tame Impala" => 5, | |
"Sigur Ros" => 5, | |
"Camera Obscura" => 5, | |
"The Soldier Thread" => 5, | |
"The Avalanches" => 5, | |
"Stars" => 5, | |
"Delta Spirit" => 5, | |
"LCD Soundsystem" => 5, | |
"Kid Cudi" => 5, | |
"Mogwai" => 5, | |
"Murs" => 5, | |
"Low" => 5, | |
"Hot Chip" => 5, | |
"Gotye" => 5, | |
"The Lonely Island" => 5, | |
"Beatles" => 5, | |
"CHRISTEENE" => 5, | |
"Wakarusa Festival - Official Page" => 5, | |
"Yeah Yeah Yeahs" => 5, | |
"Foo Fighters" => 5, | |
"Brandi Carlile" => 5, | |
"Spoon" => 5, | |
"Lykke Li" => 5, | |
"Austin Stone Worship" => 5, | |
"neiliyo" => 5, | |
"Fleetwood Mac" => 5, | |
"Feist" => 5, | |
"Ryan Bingham" => 5, | |
"Ryan Adams" => 5, | |
"Elvis Costello" => 5, | |
"The Zombies" => 5, | |
"Dimebag Darrell" => 5, | |
"Miike Snow" => 5, | |
"Norah Jones" => 5, | |
"Journey" => 5, | |
"Marvin Gaye" => 5, | |
"Simon & Garfunkel" => 5, | |
"Cold War Kids" => 5, | |
"Frightened Rabbit" => 5, | |
"Nirvana" => 5, | |
"Katy Perry" => 5, | |
"Chris Tomlin" => 5, | |
"The Cars" => 5, | |
"Garth Brooks" => 5, | |
"Peter Frampton" => 5, | |
"Imogen Heap" => 5, | |
"Ben Folds" => 5, | |
"Nick Cave" => 5, | |
"Shakey Graves" => 5, | |
"Menomena" => 5, | |
"Devendra Banhart" => 5, | |
"The Mars Volta" => 5, | |
"Brother Ali" => 5, | |
"CocoRosie" => 5, | |
"Carolyn Wonderland" => 5, | |
"EOTO" => 5, | |
"KNIFIGHT" => 5, | |
"Hollywood Gossip" => 5, | |
"Nico / Nicolas Jaar" => 5, | |
"Sunn O)))" => 5, | |
"the touchies" => 5, | |
"CA" => 5, | |
"The Head and the Heart" => 5, | |
"Pad Pusher Records" => 5, | |
"Jingle Punx" => 5, | |
"A Perfect Circle" => 5, | |
"The Ramones" => 5, | |
"Postal Service" => 5, | |
"Thelonious Monk" => 5, | |
"Freshmillions" => 5, | |
"The Sword" => 5, | |
"Local Natives" => 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment