JSFiddle - React, Tailwind, and code Playground

by lemon kazi

JavaScript

async authorize(){
        let myHeaders = new Headers();
        myHeaders.append("Authorization", `Basic 72ba43dc1ccc4afdbd8c693f0bee8068:72e14164906a49749bf1773ae9ae0e61`);
        myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

        var urlencoded = new URLSearchParams();
        urlencoded.append("grant_type", "client_credentials");

        const requestOptions = {
        method: 'POST',
        headers: myHeaders,
        body: urlencoded,
        redirect: 'follow'
        }
        
        let res = await fetch("https://accounts.spotify.com/api/token", requestOptions);
        res = await res.json();
        return res.access_token; 
    }
const access_token = await this.authorize();
console.log(access_token);