title: Spotify Refresh Token Python
body: <p>I have a python program that returns whatever song I'm currently listening to. The Access Token I get from Spotify API only lasts an hour and I'm having trouble finding an easy way to implement a refresh token into my code.</p>
  <pre><code>    SPOTIFY_GET_CURRENT_TRACK_URL = 'https://api.spotify.com/v1/me/player'
  SPOTIFY_ACCESS_TOKEN = 'BQBQMLkkLb6az9TRv-PDXFFcm4KHrofc67H12Uzs3FXaPWHETy4ivnC-WGu2Jg5wlZ_yhggGypiO0Gnv_QkNGkefTuCjNR_Tzjw4pv2W9f_9_D7-LfD2W5KVPzh2DxMmf9TNPpSn200D_Xd4AD8F_MeJc-DIlA'
  
  #Method to return the info for the currently playing track
  def get_current_track():
      response = requests.get(
          SPOTIFY_GET_CURRENT_TRACK_URL,
          headers = {
              &quot;Authorization&quot;: f&quot;Bearer {SPOTIFY_ACCESS_TOKEN}&quot;
          }
      )
      resp_json = response.json()
  
      track_id = resp_json['item']['id']
      track_name = resp_json['item']['name']
      artists = resp_json['item']['artists']
      artists_name = ', '.join(
          [artist['name'] for artist in artists]
      )
      link = resp_json['item']['external_urls']['spotify']
  
      current_track_info = {
          &quot;id&quot; : track_id,
          &quot;name&quot; : track_name,
          &quot;artists&quot; : artists_name,
          &quot;link&quot; : link
      }
  
      return current_track_info
  </code></pre>