Hi All,
I’m a bit stumped on the project, I’ve gone over my code and looked at a few solutions on the forums and I think my syntax is correct, but I’ve been starring at it for too long and could really use a fresh set of eyes.
I’m currently on step 93 of the Jammming Project. I have opted for the async-await approach rather than the chained .then() and I’m not sure if this is what is causing the issue.
From what I can see the error I’m getting is a 403 error, the documentation says
Bad OAuth request (wrong consumer key, bad nonce, expired timestamp…). Unfortunately, re-authenticating the user won’t help here.
Here is the code for my Spotify.js (I’m only including the .savePlaylist()
method as this is all that’s changed in my code base
async savePlaylist(name, trackURIs) {
if (!name && !trackURIs) {
console.log(`No name or Track URI's were found`);
return;
}
const accessToken = this.getAccessToken()
const headers = {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
};
// fetch User ID
let userID = "";
const endpoint = "https://api.spotify.com/v1/me";
let response = await fetch(endpoint, {
headers: headers,
});
if (response.ok) {
const user = await response.json();
userID = user.id;
}
// create a new playlist
const playlistEndpoint = `https://api.spotify.com/v1/users/${userID}/playlists`;
response = await fetch(playlistEndpoint, {
method: 'POST',
headers: headers,
body: JSON.stringify({name: name})
});
if (response.ok) {
const playlist = await response.json();
console.log(playlist); // testing for the response
}
throw new Error('Could not create new playlist')
},
When I paste the playlistEndpoint
URL into my browser I get an error saying that the access token is missing but I’m assuming that’s because I have pasted it straight into my browser.