<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Invalid refresh token in Spotify for Developers</title>
    <link>https://community.spotify.com/t5/Spotify-for-Developers/Invalid-refresh-token/m-p/5483508#M7525</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Plan&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Premium&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Country&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;UA&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Device&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;PC&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Operating System&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Windows 11&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Hello, trying to do an automatic access token refresh, but for some reason when I do, the query returns an error to me: {"error": "invalid_grant", "error_description": "Invalid refresh token"}&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;My refresh token is 100% correct.&lt;BR /&gt;&lt;BR /&gt;Here is my code to get the access token:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    data = {
    'grant_type': 'refresh_token',
    'refresh_token': refresh_token,
    'client_id': client_id,
    }
    headers = {
        'Authorization': 'Basic ' + base64.urlsafe_b64encode(f'{client_id}:{client_secret}'.encode('ascii')).decode(),
        'Content-Type': 'application/x-www-form-urlencoded'
    }

     response = requests.post(token_url, data=data, headers=headers)

       if response.status_code == 200:
            oauth_token = response.json()['access_token']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Jan 2023 16:56:21 GMT</pubDate>
    <dc:creator>DepsCian</dc:creator>
    <dc:date>2023-01-05T16:56:21Z</dc:date>
    <item>
      <title>Invalid refresh token</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Invalid-refresh-token/m-p/5483508#M7525</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Plan&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Premium&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Country&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;UA&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Device&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;PC&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Operating System&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Windows 11&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Hello, trying to do an automatic access token refresh, but for some reason when I do, the query returns an error to me: {"error": "invalid_grant", "error_description": "Invalid refresh token"}&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;My refresh token is 100% correct.&lt;BR /&gt;&lt;BR /&gt;Here is my code to get the access token:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    data = {
    'grant_type': 'refresh_token',
    'refresh_token': refresh_token,
    'client_id': client_id,
    }
    headers = {
        'Authorization': 'Basic ' + base64.urlsafe_b64encode(f'{client_id}:{client_secret}'.encode('ascii')).decode(),
        'Content-Type': 'application/x-www-form-urlencoded'
    }

     response = requests.post(token_url, data=data, headers=headers)

       if response.status_code == 200:
            oauth_token = response.json()['access_token']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2023 16:56:21 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Invalid-refresh-token/m-p/5483508#M7525</guid>
      <dc:creator>DepsCian</dc:creator>
      <dc:date>2023-01-05T16:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid refresh token</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Invalid-refresh-token/m-p/5483532#M7526</link>
      <description>&lt;P&gt;I recommend you to look again at "&lt;A href="https://developer.spotify.com/documentation/general/guides/authorization/code-flow/#:~:text=Request%20a%20refreshed%20Access%20Token" target="_blank" rel="noopener"&gt;Request a refreshed Access Token&lt;/A&gt;".&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2023 17:37:03 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Invalid-refresh-token/m-p/5483532#M7526</guid>
      <dc:creator>Ximzend</dc:creator>
      <dc:date>2023-01-05T17:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid refresh token</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Invalid-refresh-token/m-p/5483559#M7528</link>
      <description>&lt;P&gt;I did exactly the same thing, the problem remained.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2023 19:08:48 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Invalid-refresh-token/m-p/5483559#M7528</guid>
      <dc:creator>DepsCian</dc:creator>
      <dc:date>2023-01-05T19:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid refresh token</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Invalid-refresh-token/m-p/5483793#M7533</link>
      <description>&lt;P&gt;My solution is:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    encoded = base64.b64encode((client_id + ":" + client_secret).encode("ascii")).decode("ascii")
    data = {
    "grant_type": "client_credentials"
    }
    auth_headers = {
    "Authorization": "Basic " + encoded,
    "Content-Type": "application/x-www-form-urlencoded"
    }&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 06 Jan 2023 09:25:05 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Invalid-refresh-token/m-p/5483793#M7533</guid>
      <dc:creator>DepsCian</dc:creator>
      <dc:date>2023-01-06T09:25:05Z</dc:date>
    </item>
  </channel>
</rss>

