@@ -4,16 +4,36 @@ var SpotifyWebApi = require('../');
4
4
* This example shows how to get artists related to another artists. The endpoint is documented here:
5
5
* https://developer.spotify.com/web-api/get-related-artists/
6
6
7
- * Please note that this endpoint does not require authentication. However, using an access token
8
- * when making requests will give your application a higher rate limit.
7
+ * Please note that authorization is now required and so this example retrieves an access token using the Authorization Code Flow,
8
+ * documented here: https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow
9
9
*/
10
10
11
- var spotifyApi = new SpotifyWebApi ( ) ;
11
+ var authorizationCode =
12
+ 'AQAgjS78s64u1axMCBCRA0cViW_ZDDU0pbgENJ_-WpZr3cEO7V5O-JELcEPU6pGLPp08SfO3dnHmu6XJikKqrU8LX9W6J11NyoaetrXtZFW-Y58UGeV69tuyybcNUS2u6eyup1EgzbTEx4LqrP_eCHsc9xHJ0JUzEhi7xcqzQG70roE4WKM_YrlDZO-e7GDRMqunS9RMoSwF_ov-gOMpvy9OMb7O58nZoc3LSEdEwoZPCLU4N4TTJ-IF6YsQRhQkEOJK' ;
13
+
14
+ /* Set the credentials given on Spotify's My Applications page.
15
+ * https://developer.spotify.com/my-applications
16
+ */
17
+ var spotifyApi = new SpotifyWebApi ( {
18
+ clientId : '<insert client id>' ,
19
+ clientSecret : '<insert client secret>' ,
20
+ redirectUri : '<insert redirect URI>'
21
+ } ) ;
12
22
13
23
var artistId = '0qeei9KQnptjwb8MgkqEoy' ;
14
24
15
- spotifyApi . getArtistRelatedArtists ( artistId ) . then (
16
- function ( data ) {
25
+ spotifyApi
26
+ . authorizationCodeGrant ( authorizationCode )
27
+ . then ( function ( data ) {
28
+ console . log ( 'Retrieved access token' , data . body [ 'access_token' ] ) ;
29
+
30
+ // Set the access token
31
+ spotifyApi . setAccessToken ( data . body [ 'access_token' ] ) ;
32
+
33
+ // Use the access token to retrieve information about the user connected to it
34
+ return spotifyApi . getArtistRelatedArtists ( artistId ) ;
35
+ } )
36
+ . then ( function ( data ) {
17
37
if ( data . body . artists . length ) {
18
38
// Print the number of similar artists
19
39
console . log ( 'I got ' + data . body . artists . length + ' similar artists!' ) ;
0 commit comments