dimanche 8 mars 2015

lastfmapi - how to run simple example?

I'm new with npm. I'm using Windows. I've created a lastfmapi folder. Run the npm init and then npm install lastfmapi --save. I would like to run the simple lfm.track.getInfo example described in the lastmapi page.


I've successfully run the authenticate.js file with command node examples\authenticate.js which means that I can now use lfm.setSessionCredentials('*my username*', '*my credential*') for automatic authentication in the future.


I've created a file test.js also under the node_modules\lastfmapi\examples folder with the following copied and pasted from the web page (adding the lfm.setSessionCredentials line):



var http = require('http');
var url = require('url');
var LastfmAPI = require('../lib/lastfmapi');

var lfm = new LastfmAPI({
'api_key' : '*my key*',
'secret' : '*my secret*'
});

lfm.setSessionCredentials('*my username*', '*my credential*');

lfm.track.getInfo({
'artist' : 'Poliça',
'track' : 'Wandering Star'
}, function (err, track) {
if (err) { throw err; }
console.log(track);
});


When I run node examples\test.js I get the following error from a line in test.js:



if (err) { throw err; }
^
[object Object]


Have I followed the right procedure to run this simple example ?


Thank you


Aucun commentaire:

Enregistrer un commentaire