Skip to content

Instantly share code, notes, and snippets.

@Rchristiani
Created June 8, 2017 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rchristiani/12d61dfd45f4f3af60d3ff9cc1409ee2 to your computer and use it in GitHub Desktop.
Save Rchristiani/12d61dfd45f4f3af60d3ff9cc1409ee2 to your computer and use it in GitHub Desktop.
//This is used to get the initial token
app.auth = () => $.ajax({
method: 'POST',
headers: {
'Content-Type' : 'application/json',
'Accept': 'application/json'
},
url: 'http://proxy.hackeryou.com ',
data: JSON.stringify({
reqUrl: `https://accounts.spotify.com/api/token`,
params: {
grant_type: 'client_credentials'
},
proxyHeaders:{
//Get your own token uaing btoa()
"Authorization": `Basic YTE4YTFjMWI1YjY1NGY5MmJkOTNjYTY2MDNiZjQ0YzY6YTBlNTRjNGUzZjU4NGU2NWJlYzA4NDE2NjRkYTVmZGU=`
}
})
});
//usage is you authenticate
app.auth().then((data) => {
authHeaders = {
"Authorization" : `${data.token_type} ${data.access_token}`
};
//...
//Example below
app.getAlbumTracks = (id) => $.ajax({
url: `https://api.spotify.com/v1/albums/${id}/tracks`,
method: 'GET',
headers: authHeaders,
dataType: 'json'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment