groove-music-js
Version:
Groove Music Node.JS SDK wrapper
43 lines (32 loc) • 1.42 kB
JavaScript
var GrooveMusicWebApi = require("../");
/*
* This example shows how to search for a track. The endpoint is documented here:
* https://developer.spotify.com/web-api/search-item/
* Please note that this endpoint does not require authentication. However, using an access token
* when making requests will give your application a higher rate limit.
*/
var credentials = require("../src/creds");
var grooveApi = new GrooveMusicWebApi(credentials);
grooveApi.authenticateApp(function (err,data) {
grooveApi.searchTracks('In Cold Blood', [{ maxItems: 10 }], function (err, data) {
console.log(JSON.stringify(data,null,2));
if (err) {
console.error('Something went wrong', err.message);
return;
}
// Print some information about the results
console.log('I got ' + data.body.Tracks.TotalItemCount + ' total results!');
// Go through the first page of results
var firstPage = data.body.Tracks.Items;
console.log('The tracks in the first page are.. (source in parentheses)');
/*
* 0: All of Me (97)
* 1: My Love (91)
* 2: I Love This Life (78)
* ...
*/
firstPage.forEach(function (track, index) {
console.log(index + ': ' + track.Name + ' (' + track.Artists[0].Artist.Name + ')');
});
});
});