Created
August 31, 2018 11:35
-
-
Save joshmrallen/5aa5edea7bbbc68359ee33c851b861b4 to your computer and use it in GitHub Desktop.
File from Jammming project where we communicate with the Spotify API to get the access token to allow us to save the User's playlist to their Spotify account.
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
//variable to hold the user's access token | |
let accessToken = ''; | |
//some more variables | |
let clientID = ''; | |
let redirectURI = 'http://localhost:3000/'; | |
let url = 'https://accounts.spotify.com/authorize'; | |
//creating the Spotify module | |
const Spotify = { | |
getAccessToken() { | |
if (accessToken !== '') { | |
return accessToken; | |
} else { | |
fetch(`${url}?client_id=${clientID}&redirect_uri=${redirectURI}&response_type=token`).then(response => { | |
if(response.ok) { | |
return response.json(); | |
} | |
throw new Error('Request failed!'); | |
}, networkError => console.log(networkError.message) | |
).then(jsonResponse => { | |
//code to execute JSON response--is the response a URL with the token in it? | |
//If so, parse the response/url and find the token and save store it into accessToken | |
}); | |
}//end if statement | |
} //end getAccessToken method | |
};//end Spotify module | |
export default Spotify; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment