<?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 Error 404, 403 with certain endpoints in Spotify for Developers</title>
    <link>https://community.spotify.com/t5/Spotify-for-Developers/Error-404-403-with-certain-endpoints/m-p/5942174#M13149</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Plan&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Premium Duo&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Operating System&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Windows 10&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Hey guys, I've been working on a simple project to use the api to get my current listening information so that I can display it on a localhost website. The issue(s) I have been having is that using&amp;nbsp;me/player/currently-playing returns error &lt;STRONG&gt;404&amp;nbsp;&lt;/STRONG&gt;(not found), while using most other endpoints I get error&amp;nbsp;&lt;STRONG&gt;403&lt;/STRONG&gt;. I have been able to successfully use some endpoints under /users/ for testing. If I use just me/player I get error 403. If I make a typo I get error 404 (forbidden). . Does anyone have an idea of why this is happening? I saw there was a similar issue a few months back but I assume it is not related to that. Please forgive cluttered/redundant code as I'm not good with javascript and diagnosing errors.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;const SpotifyAPI = (function(){

    // Spotify dashboard ids
    var CLIENTID = "myid";
    var CLIENTSECRET = "mysecret";
    var redirect_url = "http://127.0.0.1:3000/index.html";

    // Define the _getToken function
    const _getToken = async () =&amp;gt; {
        const result = await fetch(`https://accounts.spotify.com/api/token`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'Authorization': 'Basic ' + btoa(CLIENTID + ':' + CLIENTSECRET)
            },
            body: 'grant_type=client_credentials&amp;amp;client_id=myid&amp;amp;client_secret=mysecret'
        });

        const data = await result.json();
        const accessToken = data.access_token;
        console.log("Access Token: ", accessToken);
        return accessToken;
    };

    // Return the _getToken function to be accessible outside
    return {
        getToken: _getToken
    };

    
})();

//get current song
const getCurrentSong = async (accessToken) =&amp;gt; {
    if (!accessToken) {
        console.error("Failed to obtain access token");
        return;
    }

    const response = await fetch('https://api.spotify.com/v1/me/player/currently-playing', {
        method: 'GET',
        headers: {
            'Authorization': 'Bearer ' + accessToken,
        }
    });

    if (response.status === 204) {
        console.log("No content: No song is currently playing");
        return null;
    }

    if (!response.ok) {
        console.error("Failed to fetch currently playing song:", response.statusText);
        return null;
    }

    const data = await response.json();
    console.log(data)
    return data.item;
};

// Example usage
SpotifyAPI.getToken()
    .then(accessToken =&amp;gt; {
        getCurrentSong(accessToken)
            .then(currentSong =&amp;gt; {
                if (currentSong) {
                    console.log("Currently playing song:", currentSong.name);
                } else {
                    console.log("No song is currently playing");
                }
            })
            .catch(error =&amp;gt; console.error("Error fetching current song:", error));
    })
    .catch(error =&amp;gt; console.error("Error fetching access token:", error));


&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Mar 2024 02:47:47 GMT</pubDate>
    <dc:creator>wesley5311</dc:creator>
    <dc:date>2024-03-14T02:47:47Z</dc:date>
    <item>
      <title>Error 404, 403 with certain endpoints</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Error-404-403-with-certain-endpoints/m-p/5942174#M13149</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Plan&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Premium Duo&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Operating System&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Windows 10&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Hey guys, I've been working on a simple project to use the api to get my current listening information so that I can display it on a localhost website. The issue(s) I have been having is that using&amp;nbsp;me/player/currently-playing returns error &lt;STRONG&gt;404&amp;nbsp;&lt;/STRONG&gt;(not found), while using most other endpoints I get error&amp;nbsp;&lt;STRONG&gt;403&lt;/STRONG&gt;. I have been able to successfully use some endpoints under /users/ for testing. If I use just me/player I get error 403. If I make a typo I get error 404 (forbidden). . Does anyone have an idea of why this is happening? I saw there was a similar issue a few months back but I assume it is not related to that. Please forgive cluttered/redundant code as I'm not good with javascript and diagnosing errors.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;const SpotifyAPI = (function(){

    // Spotify dashboard ids
    var CLIENTID = "myid";
    var CLIENTSECRET = "mysecret";
    var redirect_url = "http://127.0.0.1:3000/index.html";

    // Define the _getToken function
    const _getToken = async () =&amp;gt; {
        const result = await fetch(`https://accounts.spotify.com/api/token`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'Authorization': 'Basic ' + btoa(CLIENTID + ':' + CLIENTSECRET)
            },
            body: 'grant_type=client_credentials&amp;amp;client_id=myid&amp;amp;client_secret=mysecret'
        });

        const data = await result.json();
        const accessToken = data.access_token;
        console.log("Access Token: ", accessToken);
        return accessToken;
    };

    // Return the _getToken function to be accessible outside
    return {
        getToken: _getToken
    };

    
})();

//get current song
const getCurrentSong = async (accessToken) =&amp;gt; {
    if (!accessToken) {
        console.error("Failed to obtain access token");
        return;
    }

    const response = await fetch('https://api.spotify.com/v1/me/player/currently-playing', {
        method: 'GET',
        headers: {
            'Authorization': 'Bearer ' + accessToken,
        }
    });

    if (response.status === 204) {
        console.log("No content: No song is currently playing");
        return null;
    }

    if (!response.ok) {
        console.error("Failed to fetch currently playing song:", response.statusText);
        return null;
    }

    const data = await response.json();
    console.log(data)
    return data.item;
};

// Example usage
SpotifyAPI.getToken()
    .then(accessToken =&amp;gt; {
        getCurrentSong(accessToken)
            .then(currentSong =&amp;gt; {
                if (currentSong) {
                    console.log("Currently playing song:", currentSong.name);
                } else {
                    console.log("No song is currently playing");
                }
            })
            .catch(error =&amp;gt; console.error("Error fetching current song:", error));
    })
    .catch(error =&amp;gt; console.error("Error fetching access token:", error));


&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2024 02:47:47 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Error-404-403-with-certain-endpoints/m-p/5942174#M13149</guid>
      <dc:creator>wesley5311</dc:creator>
      <dc:date>2024-03-14T02:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: Error 404, 403 with certain endpoints</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Error-404-403-with-certain-endpoints/m-p/5942306#M13150</link>
      <description>&lt;P&gt;I'm assuming this is due to me using client credentials. I am rebuilding using PKCE and will update.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2024 03:01:52 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Error-404-403-with-certain-endpoints/m-p/5942306#M13150</guid>
      <dc:creator>wesley5311</dc:creator>
      <dc:date>2024-03-14T03:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: Error 404, 403 with certain endpoints</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Error-404-403-with-certain-endpoints/m-p/5942332#M13151</link>
      <description>&lt;P&gt;Nevermind, I don't want to prompt other people to sign in, I just want only my information accessible&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2024 03:30:36 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Error-404-403-with-certain-endpoints/m-p/5942332#M13151</guid>
      <dc:creator>wesley5311</dc:creator>
      <dc:date>2024-03-14T03:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: Error 404, 403 with certain endpoints</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Error-404-403-with-certain-endpoints/m-p/5942512#M13152</link>
      <description>&lt;P&gt;You can store your generated tokens server-side after your first login. A server-side script can use them to get the information you want to display.&lt;/P&gt;&lt;P&gt;Because an access token is only valid for 1 hour, you'll need to write code that can renew that token with the refresh token. You'll get a new refresh token when it is expired. The old stored tokens need to be replaced with the new once.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2024 06:50:49 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Error-404-403-with-certain-endpoints/m-p/5942512#M13152</guid>
      <dc:creator>Ximzend</dc:creator>
      <dc:date>2024-03-14T06:50:49Z</dc:date>
    </item>
    <item>
      <title>Re: Error 404, 403 with certain endpoints</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Error-404-403-with-certain-endpoints/m-p/5942528#M13153</link>
      <description>&lt;P&gt;Thank you for the reply. Since this is such a small project where security does not matter, would it be best for me to just use the Authorization Code Flow and refresh in the backend?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2024 06:58:48 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Error-404-403-with-certain-endpoints/m-p/5942528#M13153</guid>
      <dc:creator>wesley5311</dc:creator>
      <dc:date>2024-03-14T06:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: Error 404, 403 with certain endpoints</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Error-404-403-with-certain-endpoints/m-p/5942772#M13157</link>
      <description>&lt;P&gt;Yes, at the&amp;nbsp;&lt;SPAN&gt;backend it's fine.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2024 16:13:48 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Error-404-403-with-certain-endpoints/m-p/5942772#M13157</guid>
      <dc:creator>Ximzend</dc:creator>
      <dc:date>2024-03-14T16:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: Error 404, 403 with certain endpoints</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Error-404-403-with-certain-endpoints/m-p/5943964#M13159</link>
      <description>&lt;P&gt;Awesome, thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2024 17:36:43 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Error-404-403-with-certain-endpoints/m-p/5943964#M13159</guid>
      <dc:creator>wesley5311</dc:creator>
      <dc:date>2024-03-14T17:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: Error 404, 403 with certain endpoints</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Error-404-403-with-certain-endpoints/m-p/5947308#M13178</link>
      <description>&lt;P&gt;I have the same problem and I think the token must be valid because...&lt;/P&gt;&lt;P&gt;1) It's not even an hour yet, so it can't be overdue&lt;BR /&gt;2) I have a service running on the server side that renews the token every 50 minutes and saves it to a file&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;And I get this response&lt;/P&gt;&lt;P&gt;Error getting information about currently playing song: { "error" : { "status" : 404, "message" : "Invalid username" } }&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2024 09:46:42 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Error-404-403-with-certain-endpoints/m-p/5947308#M13178</guid>
      <dc:creator>wwwkennyseqcom</dc:creator>
      <dc:date>2024-03-16T09:46:42Z</dc:date>
    </item>
  </channel>
</rss>

