Created
December 4, 2018 14:17
-
-
Save colormono/e6a4a1090359077d7c29890cf8e84d61 to your computer and use it in GitHub Desktop.
Get Spotify API Token with Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
import qs from 'qs'; | |
// your application requests authorization | |
var CLIENT_ID = 'your-app-id'; | |
var CLIENT_SECRET = 'your-app-secret'; | |
var accessToken = ''; | |
axios({ | |
method: 'post', | |
baseURL: 'https://accounts.spotify.com/api/token', | |
data: qs.stringify({ grant_type: 'client_credentials' }), | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded', | |
Authorization: `Basic ${new Buffer( | |
CLIENT_ID + ':' + CLIENT_SECRET | |
).toString('base64')}` | |
} | |
}) | |
.then(function(response) { | |
console.log(response); | |
// save the token | |
accessToken = response.data.access_token; | |
}) | |
.catch(function(error) { | |
console.log(error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment