I have written a program that intends to add songs to my own spotify playlist.
The below is the auth code:
const { SpotifyWebApi } = require('spotify-web-api-node');
module.exports = async (req, res) => {
const spotifyApi = new SpotifyWebApi({
clientId: process.env.SPOTIFY_CLIENT_ID,
clientSecret: process.env.SPOTIFY_CLIENT_SECRET,
redirectUri: `${process.env.VERCEL_URL}/api/callback`,
});
const scopes = ['playlist-read-private', 'playlist-read-collaborative', 'playlist-modify-public', 'playlist-modify-private', 'user-read-playback-state', 'user-modify-playback-state', 'user-read-currently-playing', 'playlist-read-collaborative', 'user-read-playback-position', 'user-library-modify'];
const authorizeURL = spotifyApi.createAuthorizeURL(scopes, null);
res.writeHead(302, { Location: authorizeURL });
res.end();
};
While you’d think I’d only need playlist-modify-public and private, I included them all after testing to make sure. The /callback function returns the refresh token which I include in my code.
Yet, when I try await spotifyApi.addTracksToPlaylist(playlistId, [`spotify:track:${songId}`]);
, I get the following error:
"An error occurred while communicating with Spotify's Web API.nDetails: Insufficient client scope."
I don’t see how I can have the incorrect client scope?? I’ve made sure the tokens are correct. I don’t know what to do.