<?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 Re: Missing token 401 in Spotify for Developers</title>
    <link>https://community.spotify.com/t5/Spotify-for-Developers/Missing-token-401/m-p/5318636#M3829</link>
    <description>&lt;P&gt;I'm also having this problem, did you figure out the solution?&lt;/P&gt;</description>
    <pubDate>Tue, 21 Dec 2021 23:20:36 GMT</pubDate>
    <dc:creator>nimbyest</dc:creator>
    <dc:date>2021-12-21T23:20:36Z</dc:date>
    <item>
      <title>Missing token 401</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Missing-token-401/m-p/5109292#M1839</link>
      <description>&lt;P&gt;I'm trying to call the method to add a track to liked songs (&lt;A href="https://api.spotify.com/v1/me/tracks" target="_self"&gt;https://api.spotify.com/v1/me/tracks&lt;/A&gt;&amp;nbsp;&lt;EM&gt;PUT&lt;/EM&gt;).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I successfully receive a token with the correct scope required for the method:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
    "access_token": "BQCSsuOjuleHbd7Nee9V2cOFBIROMivTLfJjPo1VHNjOEfj-cx2GhZNVWwYPh9qcValR7QivYNTc1c8QQ4LySFiDpM8aTQ",
    "expires_in": 3600,
    "scope": "user-library-modify",
    "token_type": "Bearer"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when I call the method with this token I receive&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="javascript"&gt;{
  "error" : {
    "status" : 401,
    "message" : "Missing token"
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to call the method with a new token inside Spotify Documentation Console and got the same error.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2021 14:14:03 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Missing-token-401/m-p/5109292#M1839</guid>
      <dc:creator>mattisssa</dc:creator>
      <dc:date>2021-01-08T14:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: Missing token 401</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Missing-token-401/m-p/5109302#M1840</link>
      <description>&lt;P&gt;The code you may be interesting in:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;SPOTIFY_ACCESS_TOKEN="";

getAccessToken() {

SPOTIFY_TOKEN_URI="https://accounts.spotify.com/api/token";
if [ -z "${CLIENT_ID}" ]; then
    cecho "Invalid Client ID, please update ${USER_CONFIG_FILE}";
    showAPIHelp;
    return 1
fi
if [ -z "${CLIENT_SECRET}" ]; then
    cecho "Invalid Client Secret, please update ${USER_CONFIG_FILE}";
    showAPIHelp;
    return 1
fi
SHPOTIFY_CREDENTIALS=$(printf "${CLIENT_ID}:${CLIENT_SECRET}" | base64 | tr -d "\n"|tr -d '\r');

    cecho "Connecting to Spotify's API";

    SPOTIFY_TOKEN_RESPONSE_DATA=$( \
        curl "${SPOTIFY_TOKEN_URI}" \
            --silent \
            -X "POST" \
            -H "Authorization: Basic ${SHPOTIFY_CREDENTIALS}" \
            -d "grant_type=client_credentials&amp;amp;scope=user-library-modify" \
    )
    
    echo ${SPOTIFY_TOKEN_RESPONSE_DATA};
    
    if ! [[ "${SPOTIFY_TOKEN_RESPONSE_DATA}" =~ "access_token" ]]; then
        cecho "Autorization failed, please check ${USER_CONFG_FILE}"
        cecho "${SPOTIFY_TOKEN_RESPONSE_DATA}"
        showAPIHelp
        return 1
    fi
    
    SPOTIFY_ACCESS_TOKEN=$( \
        printf "${SPOTIFY_TOKEN_RESPONSE_DATA}" \
        | grep -E -o '"access_token":".*",' \
        | sed 's/"access_token"://g' \
        | sed 's/"//g' \
        | sed 's/,.*//g' \
    )
}

function like() {
getAccessToken;
            
            trackId=`osascript -e 'tell application "Spotify" to id of the current track' | sed -e 's/spotify:track:\(.*\)/\1/'`;

            
            SPOTIFY_LIKE_URI="https://api.spotify.com/v1/me/tracks?ids=${trackId}";
            cecho "like URL: ${SPOTIFY_LIKE_URI}";
            cecho "token: ${SPOTIFY_ACCESS_TOKEN}";
            
            results=$( \
                curl -i -X -s -G ${SPOTIFY_LIKE_URI} \
                -X "PUT" \
                -H "Authorization: Bearer ${SPOTIFY_ACCESS_TOKEN}" \
                -H "Accept: application/json" \
                -H "Content-Type: application/json"\
            )
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2021 14:17:18 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Missing-token-401/m-p/5109302#M1840</guid>
      <dc:creator>mattisssa</dc:creator>
      <dc:date>2021-01-08T14:17:18Z</dc:date>
    </item>
    <item>
      <title>Re: Missing token 401</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Missing-token-401/m-p/5318636#M3829</link>
      <description>&lt;P&gt;I'm also having this problem, did you figure out the solution?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 23:20:36 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Missing-token-401/m-p/5318636#M3829</guid>
      <dc:creator>nimbyest</dc:creator>
      <dc:date>2021-12-21T23:20:36Z</dc:date>
    </item>
  </channel>
</rss>

