This is more of a note to myself for future reference, but I hope you can find it helpful too. This is a function to console.log an access token after acquiring your Client Id and Client Secret. This is not a function to be left in your code. Get your access token and run.

const getAuth = async () => {
const clientId = 'YOUR_CLIENT_ID';
const clientSecret = 'YOUR_CLIENT_SECRET';
const headers = {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
},
auth: {
username: clientId,
password: clientSecret,
},
};
const data = {
grant_type: 'client_credentials',
};
try {
const response = await axios.post(
'https://accounts.spotify.com/api/token',
qs.stringify(data),
headers
);
console.log(response.data.access_token);
return response.data.access_token;
} catch (error) {
console.log(error);
}
};

That’s it. If you have any questions. Feel free to reach out to me on Twitter.

--

--

Joseph Perez

Joseph Perez

I am a Jr. Web Developer, coding bootcamp graduate, and an ex-pro gamer.