Created
June 8, 2017 18:35
-
-
Save Rchristiani/12d61dfd45f4f3af60d3ff9cc1409ee2 to your computer and use it in GitHub Desktop.
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
//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