spotify-client.py•817 B
import base64
import requests
class SpotifyClient:
def __init__(self, client_id: str, client_secret: str, redirect_uri: str):
self.client_id = client_id
self.client_secret = client_secret
self.redirect_uri = redirect_uri
def get_access_token(self, code: str):
authOptions = {
"data": {
"code": code,
"redirect_uri": self.redirect_uri,
"grant_type": 'authorization_code'
},
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": f"Basic {base64.b64encode(f'{self.client_id}:{self.client_secret}'.encode()).decode()}"
}
}
response = requests.post("https://accounts.spotify.com/api/token", **authOptions)