import requests


def token(code, redirect_uri, client_id, client_secret):
    """Generates access token used to call Spotify API 

    Args:
        code (str): Authorization code used to generate token
        redirect_uri (str): Allowed redirect URL set in Spotify's developer dashboard
        client_id (str): Application's id needed for OAuth 2.0 
        client_secret (str): Application's secret needed for OAuth 2.0 

    Returns:
        token (str): Access token for Spotify API 

    See:
        https://developer.spotify.com/documentation/general/guides/authorization-guide/

    """
    params = {
        "grant_type":    "authorization_code",
        "client_id":    client_id,
        "client_secret": client_secret,
        "code":          code,
        "redirect_uri":  redirect_uri
    }
    return requests.post(url='https://accounts.spotify.com/api/token', data=params).json()['access_token']