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>'));
});
});
});```