Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added example program which loads a track from a given link (URI or URL)

  • Loading branch information...
commit 172211f5bb3979b4e720fb3a9dffa20aef58ddf8 1 parent aea85ba
@rsms rsms authored
Showing with 25 additions and 0 deletions.
  1. +25 −0 examples/track-from-link.js
View
25 examples/track-from-link.js
@@ -0,0 +1,25 @@
+/*
+ This example shows how to load a track from a link (URI or URL).
+
+ You can give a link as the first argument on the command line, or run the
+ script without arguments to fetch a predefined track.
+*/
+var sys = require('sys'),
+ spotify = require('../spotify'),
+ account = require('../account');
+
+var link = 'spotify:track:01gCUID7bHTcp6JzeTfpIe';
+if (process.argv.length > 2) link = process.argv[2];
+
+var session = new spotify.Session({ applicationKey: account.applicationKey });
+session.addListener('logMessage', sys.print);
+session.login(account.username, account.password, function (err) {
+ if (err) return sys.error(err.stack || err);
+ session.getTrackByLink(link, function(err, track) {
+ if (err)
+ sys.error(err.stack || err);
+ else
+ sys.puts('track loaded:\n'+sys.inspect(track));
+ session.logout();
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.