Back to articles
How to Scrape Spotify Playlist and Track Data

How to Scrape Spotify Playlist and Track Data

via Dev.to WebdevАлексей Спинов

Spotify has a free Web API with generous rate limits. Spotify Web API // Get access token (client credentials flow) async function getSpotifyToken ( clientId , clientSecret ) { const res = await fetch ( " https://accounts.spotify.com/api/token " , { method : " POST " , headers : { " Authorization " : " Basic " + btoa ( clientId + " : " + clientSecret ), " Content-Type " : " application/x-www-form-urlencoded " }, body : " grant_type=client_credentials " }); const data = await res . json (); return data . access_token ; } // Search tracks async function searchTracks ( query , token ) { const url = `https://api.spotify.com/v1/search?q= ${ encodeURIComponent ( query )} &type=track&limit=10` ; const res = await fetch ( url , { headers : { " Authorization " : " Bearer " + token } }); const data = await res . json (); return data . tracks . items . map ( t => ({ name : t . name , artist : t . artists [ 0 ]. name , album : t . album . name , popularity : t . popularity , preview : t . preview_

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
8 views

Related Articles