Skip to content

Commit b6f94e6

Browse files
authored
Update URLs, comments and ES5 -> ES6 (#253)
1 parent 1a0496f commit b6f94e6

8 files changed

+55
-64
lines changed

examples/access-token-refresh.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
var SpotifyWebApi = require('../');
1+
const SpotifyWebApi = require('../');
22

33
/**
44
* This example refreshes an access token. Refreshing access tokens is only possible access tokens received using the
55
* Authorization Code flow, documented here: https://developer.spotify.com/spotify-web-api/authorization-guide/#authorization_code_flow
66
*/
77

8-
/* Retrieve a code as documented here:
9-
* https://developer.spotify.com/spotify-web-api/authorization-guide/#authorization_code_flow
8+
/* Retrieve an authorization code as documented here:
9+
* https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow
10+
* or in the Authorization section of the README.
1011
*
1112
* Codes are given for a set of scopes. For this example, the scopes are user-read-private and user-read-email.
1213
* Scopes are documented here:
13-
* https://developer.spotify.com/spotify-web-api/using-scopes/
14+
* https://developer.spotify.com/documentation/general/guides/scopes/
1415
*/
15-
var authorizationCode =
16-
'AQAgjS78s64u1axMCBCRA0cViW_ZDDU0pbgENJ_-WpZr3cEO7V5O-JELcEPU6pGLPp08SfO3dnHmu6XJikKqrU8LX9W6J11NyoaetrXtZFW-Y58UGeV69tuyybcNUS2u6eyup1EgzbTEx4LqrP_eCHsc9xHJ0JUzEhi7xcqzQG70roE4WKM_YrlDZO-e7GDRMqunS9RMoSwF_ov-gOMpvy9OMb7O58nZoc3LSEdEwoZPCLU4N4TTJ-IF6YsQRhQkEOJK';
16+
const authorizationCode =
17+
'<insert authorization code with user-read-private and user-read-email scopes>';
1718

1819
/**
19-
* Set the credentials given on Spotify's My Applications page.
20-
* https://developer.spotify.com/my-applications
20+
* Get the credentials from Spotify's Dashboard page.
21+
* https://developer.spotify.com/dashboard/applications
2122
*/
22-
var spotifyApi = new SpotifyWebApi({
23+
const spotifyApi = new SpotifyWebApi({
2324
clientId: '<insert client id>',
2425
clientSecret: '<insert client secret>',
2526
redirectUri: '<insert redirect URI>'
2627
});
2728

2829
// When our access token will expire
29-
var tokenExpirationEpoch;
30+
let tokenExpirationEpoch;
3031

3132
// First retrieve an access token
3233
spotifyApi.authorizationCodeGrant(authorizationCode).then(
@@ -53,7 +54,7 @@ spotifyApi.authorizationCodeGrant(authorizationCode).then(
5354
);
5455

5556
// Continually print out the time left until the token expires..
56-
var numberOfTimesUpdated = 0;
57+
let numberOfTimesUpdated = 0;
5758

5859
setInterval(function() {
5960
console.log(

examples/access-token-using-client-credentials.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
var SpotifyWebApi = require('../');
1+
const SpotifyWebApi = require('../');
22

33
/**
4-
* This example retrives an access token using the Client Credentials Flow. It's well documented here:
5-
* https://developer.spotify.com/web-api/authorization-guide/#client_credentials_flow
6-
*/
7-
8-
/*
9-
* https://developer.spotify.com/spotify-web-api/using-scopes/
4+
* This example retrieves an access token using the Client Credentials Flow, documented at:
5+
* https://developer.spotify.com/documentation/general/guides/authorization-guide/#client-credentials-flow
106
*/
117

128
/**
13-
* Set the credentials given on Spotify's My Applications page.
14-
* https://developer.spotify.com/my-applications
9+
* Get the credentials from Spotify's Dashboard page.
10+
* https://developer.spotify.com/dashboard/applications
1511
*/
16-
var spotifyApi = new SpotifyWebApi({
12+
const spotifyApi = new SpotifyWebApi({
1713
clientId: '<insert client id>',
1814
clientSecret: '<insert client secret>'
1915
});

examples/add-remove-replace-tracks-in-a-playlist.js

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
1-
var SpotifyWebApi = require('../');
1+
const SpotifyWebApi = require('../');
22

33
/**
4-
* This example demonstrates adding tracks, removing tracks, and replacing tracks in a playlist. At this time of writing this
5-
* documentation, this is the available playlist track modification features in the Spotify Web API.
4+
* This example demonstrates adding tracks, removing tracks, and replacing tracks in a playlist. At the time of writing this
5+
* documentation, this is the available playlist track modification feature in the Spotify Web API.
66
*
77
* Since authorization is required, this example retrieves an access token using the Authorization Code Grant flow,
8-
* documented here: https://developer.spotify.com/spotify-web-api/authorization-guide/#authorization_code_flow
8+
* documented here: https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow
99
*
1010
* Codes are given for a set of scopes. For this example, the scopes are playlist-modify-public.
1111
* Scopes are documented here:
12-
* https://developer.spotify.com/spotify-web-api/using-scopes/
12+
* https://developer.spotify.com/documentation/general/guides/scopes/
1313
*/
1414

15-
/* This code is hardcoded. For a working implementation, the code needs to be retrieved from the user. See documentation about
16-
* the Authorization Code flow for more information.
15+
/* Obtain the `authorizationCode` below as described in the Authorization section of the README.
1716
*/
18-
var authorizationCode =
17+
const authorizationCode =
1918
'<insert authorization code with playlist-modify-public scope>';
2019

2120
/**
22-
* Set the credentials given on Spotify's My Applications page.
23-
* https://developer.spotify.com/my-applications
21+
* Get the credentials from Spotify's Dashboard page.
22+
* https://developer.spotify.com/dashboard/applications
2423
*/
25-
var spotifyApi = new SpotifyWebApi({
24+
const spotifyApi = new SpotifyWebApi({
2625
clientId: '<insert client id>',
2726
clientSecret: '<insert client secret>',
2827
redirectUri: '<insert redirect URI>'
2928
});
3029

31-
var playlistId;
30+
let playlistId;
3231

3332
// First retrieve an access token
3433
spotifyApi
@@ -81,6 +80,5 @@ spotifyApi
8180
console.log('Ok. Tracks replaced!');
8281
})
8382
.catch(function(err) {
84-
console.log(err.message);
85-
console.log('Something went wrong!');
83+
console.log('Something went wrong:', err.message);
8684
});

examples/add-tracks-to-a-playlist.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
var SpotifyWebApi = require('../');
1+
const SpotifyWebApi = require('../');
22

33
/**
44
* This example demonstrates adding tracks to a specified position in a playlist.
55
*
66
* Since authorization is required, this example retrieves an access token using the Authorization Code Grant flow,
7-
* documented here: https://developer.spotify.com/spotify-web-api/authorization-guide/#authorization_code_flow
7+
* documented here: https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow
88
*
99
* Codes are given for a set of scopes. For this example, the scopes are playlist-modify-public.
1010
* Scopes are documented here:
11-
* https://developer.spotify.com/spotify-web-api/using-scopes/
11+
* https://developer.spotify.com/documentation/general/guides/scopes/
1212
*/
1313

14-
/* This code is hardcoded. For a working implementation, the code needs to be retrieved from the user. See documentation about
15-
* the Authorization Code flow for more information.
14+
/* Obtain the `authorizationCode` below as described in the Authorization section of the README.
1615
*/
17-
var authorizationCode = '<insert authorization code>';
16+
const authorizationCode = '<insert authorization code>';
1817

1918
/**
20-
* Set the credentials given on Spotify's My Applications page.
21-
* https://developer.spotify.com/my-applications
19+
* Get the credentials from Spotify's Dashboard page.
20+
* https://developer.spotify.com/dashboard/applications
2221
*/
23-
var spotifyApi = new SpotifyWebApi({
22+
const spotifyApi = new SpotifyWebApi({
2423
clientId: '<insert client id>',
2524
clientSecret: '<insert client secret>',
2625
redirectUri: '<insert redirect URI>'
@@ -46,5 +45,5 @@ spotifyApi
4645
console.log('Added tracks to the playlist!');
4746
})
4847
.catch(function(err) {
49-
console.log('Something went wrong!', err.message);
48+
console.log('Something went wrong:', err.message);
5049
});

examples/get-info-about-current-user.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
var SpotifyWebApi = require('../');
1+
const SpotifyWebApi = require('../');
22

33
/**
44
* This example retrieves information about the 'current' user. The current user is the user that has
55
* authorized the application to access its data.
66
*/
77

88
/* Retrieve a code as documented here:
9-
* https://developer.spotify.com/spotify-web-api/authorization-guide/#authorization_code_flow
9+
* https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow
1010
*
1111
* Codes are given for a set of scopes. For this example, the scopes are user-read-private and user-read-email.
1212
* Scopes are documented here:
13-
* https://developer.spotify.com/spotify-web-api/using-scopes/
13+
* https://developer.spotify.com/documentation/general/guides/scopes/
1414
*/
15-
var authorizationCode =
16-
'AQAgjS78s64u1axMCBCRA0cViW_ZDDU0pbgENJ_-WpZr3cEO7V5O-JELcEPU6pGLPp08SfO3dnHmu6XJikKqrU8LX9W6J11NyoaetrXtZFW-Y58UGeV69tuyybcNUS2u6eyup1EgzbTEx4LqrP_eCHsc9xHJ0JUzEhi7xcqzQG70roE4WKM_YrlDZO-e7GDRMqunS9RMoSwF_ov-gOMpvy9OMb7O58nZoc3LSEdEwoZPCLU4N4TTJ-IF6YsQRhQkEOJK';
15+
const authorizationCode =
16+
'<insert authorization code with user-read-private and user-read-email scopes>';
1717

18-
/* Set the credentials given on Spotify's My Applications page.
19-
* https://developer.spotify.com/my-applications
18+
/* Get the credentials from Spotify's Dashboard page.
19+
* https://developer.spotify.com/dashboard/applications
2020
*/
21-
var spotifyApi = new SpotifyWebApi({
21+
const spotifyApi = new SpotifyWebApi({
2222
clientId: '<insert client id>',
2323
clientSecret: '<insert client secret>',
2424
redirectUri: '<insert redirect URI>'
@@ -50,5 +50,5 @@ spotifyApi
5050
console.log('This user has a ' + data.body.product + ' account');
5151
})
5252
.catch(function(err) {
53-
console.log('Something went wrong', err.message);
53+
console.log('Something went wrong:', err.message);
5454
});

examples/get-related-artists.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ spotifyApi.getArtistRelatedArtists(artistId).then(
2424
}
2525
},
2626
function(err) {
27-
console.log('Something went wrong..', err.message);
27+
console.log('Something went wrong:', err.message);
2828
}
2929
);

examples/get-top-tracks-for-artist.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
var SpotifyWebApi = require('../');
1+
const SpotifyWebApi = require('../');
22

33
/**
44
* This example retrieves the top tracks for an artist.
5-
* https://developer.spotify.com/spotify-web-api/get-artists-top-tracks/
5+
* https://developer.spotify.com/documentation/web-api/reference/artists/get-artists-top-tracks/
66
*/
77

88
/**
@@ -11,9 +11,9 @@ var SpotifyWebApi = require('../');
1111
*
1212
* Since it's not necessary to get an access token connected to a specific user, this example
1313
* uses the Client Credentials flow. This flow uses only the client ID and the client secret.
14-
* https://developer.spotify.com/spotify-web-api/authorization-guide/#client_credentials_flow
14+
* https://developer.spotify.com/documentation/general/guides/authorization-guide/#client-credentials-flow
1515
*/
16-
var spotifyApi = new SpotifyWebApi({
16+
const spotifyApi = new SpotifyWebApi({
1717
clientId: '<insert client id>',
1818
clientSecret: '<insert client secret>'
1919
});

examples/search-for-tracks.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ spotifyApi
3939

4040
// Go through the first page of results
4141
var firstPage = data.body.tracks.items;
42-
console.log(
43-
'The tracks in the first page are.. (popularity in parentheses)'
44-
);
42+
console.log('The tracks in the first page are (popularity in parentheses):');
4543

4644
/*
4745
* 0: All of Me (97)
@@ -52,7 +50,6 @@ spotifyApi
5250
firstPage.forEach(function(track, index) {
5351
console.log(index + ': ' + track.name + ' (' + track.popularity + ')');
5452
});
55-
})
56-
.catch(function(err) {
53+
}).catch(function(err) {
5754
console.log('Something went wrong:', err.message);
5855
});

0 commit comments

Comments
 (0)