简体   繁体   中英

(Spotify Web API) Create New Playlist - POST request returning 'Error 403 (Forbidden)'

Here is the link to the Web API notes on how to create a new playlist. https://developer.spotify.com/web-api/create-playlist/

As far as I understand, the POST requests the url https://api.spotify.com/v1/users/{user_id}/playlists . This is requested while passing the access token and data. The content type of the data being 'application/json'.

For some reason this is failing and returning a Error 403 (Forbidden) in the console.

Anything I'm missing?

 //(playlistName, userId, accessToken) are passed to this. var urlString = 'https://api.spotify.com/v1/users/' + userId + '/playlists'; var jsonData = { "name": playlistName, "public": false }; $.ajax({ type: 'POST', url: urlString, data: jsonData, dataType: 'json', headers: { 'Authorization': 'Bearer ' + accessToken }, contentType: 'application/json', success: function(result) { console.log('Woo! :)'); }, error: function() { console.log('Error! :('); } }) 

Having tried your example, I get a 401 unauthorized when filling in bogus data. So you are authorized, but the API really does not grant you the rights ( 403 forbidden ).

Please have a look at the authorization guide. I am pretty sure, your error is there. Especially have a look at scope . You might simply not grant enough power in the login. And therefore ending up with only public access, which does not include adding playlists.

I cite form the API docs:

To be able to create private playlists, the user must have granted the playlist-modify-private scope.

https://developer.spotify.com/web-api/authorization-guide/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM