Get Top Tracks
To display the user’s top tracks, you can use the getTopTracks
method. This method returns an array of the user’s top tracks.
async function getTopTracks(userId, amount, offset) { try { const tracks = await vibify.getTopTracks(userId, amount, offset); console.log('Top Tracks:', tracks); } catch (error) { console.error('Error:', error); }}
getTopTracks('user-id', 1, 0);
Or with cURL:
curl -H "x-api-key:: (your api key)" http://localhost:3000/user/(user-id)/top-tracks?amount=1
Response
{ "items":[ { "album":{ "album_type":"SINGLE", "total_tracks":1, "available_markets":[ "AR", "AU", "..." ], "external_urls":{ "spotify":"https://open.spotify.com/album/7d0WlrQjs729QYYtdyS8U4" }, "href":"https://api.spotify.com/v1/albums/7d0WlrQjs729QYYtdyS8U4", "id":"7d0WlrQjs729QYYtdyS8U4", "images":[ { "url":"https://i.scdn.co/image/ab67616d0000b273636bfdda73257b1b3dfd94c8", "height":640, "width":640 }, { "url":"https://i.scdn.co/image/ab67616d00001e02636bfdda73257b1b3dfd94c8", "height":300, "width":300 }, { "url":"https://i.scdn.co/image/ab67616d00004851636bfdda73257b1b3dfd94c8", "height":64, "width":64 } ], "name":"How It Should Look", "release_date":"2023-03-30", "release_date_precision":"day", "type":"album", "uri":"spotify:album:7d0WlrQjs729QYYtdyS8U4", "artists":[ { "external_urls":{ "spotify":"https://open.spotify.com/artist/3RfeWhoxAqlNRNcywG7RJj" }, "href":"https://api.spotify.com/v1/artists/3RfeWhoxAqlNRNcywG7RJj", "id":"3RfeWhoxAqlNRNcywG7RJj", "name":"Pigeon John", "type":"artist", "uri":"spotify:artist:3RfeWhoxAqlNRNcywG7RJj" } ] }, "artists":[ { "external_urls":{ "spotify":"https://open.spotify.com/artist/3RfeWhoxAqlNRNcywG7RJj" }, "href":"https://api.spotify.com/v1/artists/3RfeWhoxAqlNRNcywG7RJj", "id":"3RfeWhoxAqlNRNcywG7RJj", "name":"Pigeon John", "type":"artist", "uri":"spotify:artist:3RfeWhoxAqlNRNcywG7RJj" } ], "available_markets":[ "AR", "AU", "..." ], "disc_number":1, "duration_ms":140930, "explicit":false, "external_ids":{ "isrc":"QZ5AB2373416" }, "external_urls":{ "spotify":"https://open.spotify.com/track/3WX0UO7abqGFFsAukJ96ds" }, "href":"https://api.spotify.com/v1/tracks/3WX0UO7abqGFFsAukJ96ds", "id":"3WX0UO7abqGFFsAukJ96ds", "name":"How It Should Look", "popularity":27, "preview_url":"https://p.scdn.co/mp3-preview/73616ea8471d61ad5d2f19359248e8260fab94aa?cid=bd747a3119c04456abd0edfac3d9d42c", "track_number":1, "type":"track", "uri":"spotify:track:3WX0UO7abqGFFsAukJ96ds", "is_local":false } ]}