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

166
Visualizações
Trying to create a website that used spotifyapi to print artist related artist

I found how to use the getArtistRelatedArtists but I don't know how to call it and use it to print out related artists.

I made something like relArtist = data.artists.item[0].relatedArtist but i'm pretty sure theres nothing like .relatedArtist

relArtist means relatedArtist. i obv haven't printed it out yet but i don't know where to even start.

var express = require('express');
var app = express();

var SpotifyWebApi = require('spotify-web-api-node');

var spotifyApi = new SpotifyWebApi({
  clientId : process.env.CLIENT_ID,
  clientSecret : process.env.CLIENT_SECRET,
});

// Authenticate our app with Spotify
spotifyApi.clientCredentialsGrant()
  .then(function(data) {
    console.log('The access token expires in ' + data.body['expires_in']);
    console.log('The access token is ' + data.body['access_token']);

    // Save the access token so that it's used in future calls
    spotifyApi.setAccessToken(data.body['access_token']);
  }, function(err) {
    console.log('Something went wrong when retrieving an access token', err.message);
  });


// http://expressjs.com/en/starter/static-files.html
app.use(express.static('public'));

// http://expressjs.com/en/starter/basic-routing.html
app.get("/", function (request, response) {
  response.sendFile(__dirname + '/views/index.html');
});

app.get("/search", function (request, response) {
  
  let query = request.query.query;
  console.log(request)
  
  // Search for artists using the query parameter on the request
  spotifyApi.searchArtists(query)
  .then(function(data) {
    console.log(data.body);
    
    // Return the JSON object from the API
    response.send(data.body);
  }, function(err) {
    console.log(err)
  });
  
  spotifyApi.getArtistRelatedArtists(query)
  .then(function(data) {
    console.log(data.body);
    
    // Return the JSON object from the API
    response.send(data.body);
  }, function(err) {
    console.log(err)
  });
  
});

// listen for requests :)
var listener = app.listen(process.env.PORT, function () {
  console.log('Your app is listening on port ' + listener.address().port);
});

-----------------------------
$(function() {
  console.log('hello world :o');

  $('form').submit(function(event) {
    event.preventDefault();
    
    let query = $('input').val();
    
    $.get('/search?' + $.param({query: query}), function(data) {
      $('#results').empty();
      $('input[type="text"]').val('');
      $('input').focus();
      
      // Get the first ID from the JSON object
      let id = data.artists.items[0].id
      let relArtist = data.artists.items[0].relatedArtist
      $('#results').append($('<p>' + id + '</p>'));

    });
  });

});```


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