Skip to content

Instantly share code, notes, and snippets.

@mager
Created February 10, 2012 19:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mager/1792061 to your computer and use it in GitHub Desktop.
Save mager/1792061 to your computer and use it in GitHub Desktop.
Spotify Apps API - Get a user's top tracks (JS)
/* Instantiate the global sp object; include models & views */
var sp = getSpotifyApi(1);
var models = sp.require("sp://import/scripts/api/models");
var views = sp.require("sp://import/scripts/api/views");
var toplist = new models.Toplist();
/* Set attributes of the Toplist object */
toplist.toplistType = models.TOPLISTTYPE.REGION;
toplist.userName = models.TOPLISTUSER_CURRENT;
toplist.matchType = models.TOPLISTMATCHES.TRACKS;
toplist.observe(models.EVENT.CHANGE, function() {
toplist.results.forEach(function(track) {
var link = '<li><a href="' + track.uri + '">' + track.name + '</a></li>';
$('#toplist').append(link);
});
});
toplist.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment