Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

298
Visualizações
User input as search query for Spotify WEB-API

I'm trying to display a spotify player that lists all the tracks in a specific album given by the user input. The authorization and maping of the data works fine and i can confirm that i actually get the correct URI for the specific album in the console.

How can i pass the URI data to the player's adress? I tried passing the value as a variable and simply adding it to the path but didn't work for me. If i paste the URI directly from the console however it works as intended

HTML

  <!DOCTYPE html>
  <html>
    <head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <link rel="stylesheet" href="style.css">
    </head>
    <body>
    
    
     <p class="songURI"></p>
    

     <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

      //SPOTIFY PLAYER, with pasted URI. Here, i would like to use the data i retrieve from the script file instead
     <iframe src="https://open.spotify.com/embed?uri=spotify:album:6s9twOs9wMKOEluU5dkBE0" width="300" height="380" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>
     <script src="spotifyscript.js"></script>
   </body>
</html>

JS

 var accessToken = 'TOKEN';

 fetch('https://api.spotify.com/v1/search?q='+search+'&type=album&market=SE&limit=5&offset=5', {
        method: 'GET', headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
            'Authorization': 'Bearer ' + accessToken
        }
    })
    .then(response => response.json()) 
    .then(data => {
      const spotifylist = data.albums.items;
      console.log(data); 

  spotifylist.map((items) => {
    const track = items.name;
    const uri = items.uri;
    console.log(uri); //Logs the URI
    document.querySelector('.movies').innerHTML += track;
    document.getElementsByClassName('.songURI').innerHTML += uri;
    
  })
})

.catch(err => {
console.error(err);
});
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda