1️⃣ Obtener tu API Key de Spotify

2️⃣ Token de acceso vía Client-Credentials

const getToken = async () => {
  const response = await fetch('https://accounts.spotify.com/api/token', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'Authorization': 'Basic ' + btoa(clientId + ':' + clientSecret)
    },
    body: 'grant_type=client_credentials'
  });
  const data = await response.json();
  return data.access_token;
};

3️⃣ Buscar pistas con Fetch

const searchTracks = async (query, token) => {
  const res = await fetch(`https://api.spotify.com/v1/search?q=${query}&type=track&limit=10`, {
    headers: { 'Authorization': 'Bearer ' + token }
  });
  const data = await res.json();
  return data.tracks.items;
};

4️⃣ Paginación con next/previous

const getPage = async (url, token) => {
  const res = await fetch(url, {
    headers: { 'Authorization': 'Bearer ' + token }
  });
  return await res.json();
};
// Uso: const nextPage = await getPage(tracks.next, token);

5️⃣ Reproductor vanilla JS + Audio

Carga preview URL devuelta por Spotify:

const playPreview = (url) => {
  const audio = new Audio(url);
  audio.volume = 0.8;
  audio.play();
};
Demo abajo 👇