-
Notifications
You must be signed in to change notification settings - Fork 497
/
Copy pathget-related-artists.js
49 lines (40 loc) · 1.84 KB
/
get-related-artists.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var SpotifyWebApi = require('../');
/*
* This example shows how to get artists related to another artists. The endpoint is documented here:
* https://developer.spotify.com/web-api/get-related-artists/
* Please note that authorization is now required and so this example retrieves an access token using the Authorization Code Flow,
* documented here: https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow
*/
var authorizationCode =
'AQAgjS78s64u1axMCBCRA0cViW_ZDDU0pbgENJ_-WpZr3cEO7V5O-JELcEPU6pGLPp08SfO3dnHmu6XJikKqrU8LX9W6J11NyoaetrXtZFW-Y58UGeV69tuyybcNUS2u6eyup1EgzbTEx4LqrP_eCHsc9xHJ0JUzEhi7xcqzQG70roE4WKM_YrlDZO-e7GDRMqunS9RMoSwF_ov-gOMpvy9OMb7O58nZoc3LSEdEwoZPCLU4N4TTJ-IF6YsQRhQkEOJK';
/* Set the credentials given on Spotify's My Applications page.
* https://developer.spotify.com/my-applications
*/
var spotifyApi = new SpotifyWebApi({
clientId: '<insert client id>',
clientSecret: '<insert client secret>',
redirectUri: '<insert redirect URI>'
});
var artistId = '0qeei9KQnptjwb8MgkqEoy';
spotifyApi
.authorizationCodeGrant(authorizationCode)
.then(function(data) {
console.log('Retrieved access token', data.body['access_token']);
// Set the access token
spotifyApi.setAccessToken(data.body['access_token']);
// Use the access token to retrieve information about the user connected to it
return spotifyApi.getArtistRelatedArtists(artistId);
})
.then(function(data) {
if (data.body.artists.length) {
// Print the number of similar artists
console.log('I got ' + data.body.artists.length + ' similar artists!');
console.log('The most similar one is ' + data.body.artists[0].name);
} else {
console.log("I didn't find any similar artists.. Sorry.");
}
},
function(err) {
console.log('Something went wrong:', err.message);
}
);