Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jrthib/5154305 to your computer and use it in GitHub Desktop.
Save jrthib/5154305 to your computer and use it in GitHub Desktop.
/* 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