Created
February 10, 2012 20:07
-
-
Save mager/1792366 to your computer and use it in GitHub Desktop.
Spotify Apps API - Get a user's listening history from Facebook (JS)
This file contains hidden or 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
/* Instantiate the global sp object; include models & views */ | |
var sp = getSpotifyApi(1); | |
var auth = sp.require('sp://import/scripts/api/auth'); | |
var permissions = ['user_actions.music']; | |
var app_id = '126891607432106'; | |
var request_url = 'https://graph.facebook.com/me/music.listens'; | |
auth.authenticateWithFacebook(app_id, permissions, { | |
onSuccess : function(accessToken, ttl) { | |
var url = request_url + '?access_token=' + accessToken; | |
$.getJSON(url, function(data) { | |
var listens = data.data; | |
for(var i=0;i<listens.length;i++) { | |
var tracklink = listens[i].data.song.url; | |
var trackname = listens[i].data.song.title; | |
$('#listens').append('<li><a href="' + tracklink + '">' + trackname + '</a></li>'); | |
} | |
}); | |
}, | |
onFailure : function(error) { | |
console.log("Authentication failed with error: " + error); | |
}, | |
onComplete : function() { } | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this! Going to play around...Does this always work? What if a user doesn't post their song to Facebook?