dimanche 19 avril 2015

Node.js and Spotify API - [Object] for all tracks in JSON playlist?

I'm new to Node.js and JSON in general and I'm trying to access each individual song in a playlist object returned by the spotify API. When I get the JSON object, it returns me a bunch of [Object] things in "items", which is where the tracks should be.


My code:



function iterPlaylists(callback)
{
console.log("POINT C");
listID = playlists[i].id;
console.log("Playlist name : "+ playlists[i].name + " Playlist ID: " + playlists[i].id );
callback();
}
//}, 800);

function getTrax(playlist)
{
iterPlaylists(function(){
spotifyApi.getPlaylist(id, listID)
.then(function(data) {
console.log('The playlist contains these tracks', data.body);
}, function(err) {
console.log('Something went wrong!', err);
});
});
}
setTimeout(function(){
getTrax(playlists);
}, 2000);


The output:



Playlist name : thug lif3 Playlist ID: 41moBc7H5bWrR3iiY0Zu9Q
The playlist contains these tracks { collaborative: false,
description: null,
external_urls: { spotify: 'http://ift.tt/1EfJxhY' },
followers: { href: null, total: 0 },
href: 'http://ift.tt/1OXuJGl',
id: '41moBc7H5bWrR3iiY0Zu9Q',
images:
[ { height: 640,
url: 'http://ift.tt/1EfJxi0',
width: 640 } ],
name: 'thug lif3',
owner:
{ external_urls: { spotify: 'http://ift.tt/1OXuJGo' },
href: 'http://ift.tt/1EfJxi2',
id: '1256443176',
type: 'user',
uri: 'spotify:user:1256443176' },
public: true,
snapshot_id: 'wjANf1rS9Nj1SFjRYTr4U2gKPtaYH0tq/5lZPorpDjCpSIg0rTxx5H+KIuFZebZp',
tracks:
{ href: 'http://ift.tt/1OXuJGr
00',
items: [ **[Object], [Object], [Object]** ],
limit: 100,
next: null,
offset: 0,
previous: null,
total: 3 },
type: 'playlist',
uri: 'spotify:user:1256443176:playlist:41moBc7H5bWrR3iiY0Zu9Q' }


Sorry for the messy block of output, but I'm really stumped on what to do here. Are these [object] things a sign of a nullity, or is there some way I can parse them and get the data from them? The API explorer on Spotify's website shows the actual track objects after "Items", so I'm confused as to why my app request isn't doing the same.


Aucun commentaire:

Enregistrer un commentaire