title: Spotify API fetch authorization code from redirect_uri
body: <p>I'm trying to get authorization for my app and my Spotify account. Don't need the feature working inside the app for every user. Because there is no app yet. Just want to try some things first. And now I'm aware of spotipy, I should probably use the library. At first, I was trying just paste links in the browser following the instruction below. The first step works fine. But when I'm trying to exchange auth code with token I'm always getting an error. I'm thinking maybe the auth code has an extremely short lifetime, and it's always too late when I've pasted auth code in the new link.</p>
  
  <p>So, the question is: could I somehow fetch the code that appears in the redirect_uri after performing GET request, and then pass it as one of the parameters to the POST request.    </p>
  
  <p>The guide from spotify - <a href="https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorizaton-code-flow" rel="nofollow noreferrer">https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorizaton-code-flow</a></p>
  
  <pre><code>import requests
  import config
  import secrets
  import string
  
  
  URL_AUTH = 'https://accounts.spotify.com/authorize'
  URL_TOKEN = 'https://accounts.spotify.com/api/token'
  symbols = string.ascii_lowercase + string.digits
  STATE = ''.join(secrets.choice(symbols) for _ in range(12))
  
  params_auth = {
                  'client_id': config.CLIENT_ID,
                  'response_type': 'code',
                  'redirect_uri': 'https://example.com/callback',
                  'scope': 'user-read-currently-playing',
                  'state': STATE
  }
  
  data_token = {
                  'grant_type': "authorization_code",
                  # how can I get the auth code 'code': auth_code,
                  'redirect_uri': 'https://example.com/callback',
                  'client_id': config.CLIENT_ID,
                  'client_secret': config.CLIENT_SECRET
  }
  
  app_auth = requests.get(url=URL_AUTH, params=params_auth)
  
  access_token = requests.post(url=URL_TOKEN, data=data_token)
  </code></pre>