3

I'm using the Spotify API and basically I want to be able to access a user's playlists, modify playlists, and create new playlists. I was using the JavaScript wrapper for client side (https://github.com/JMPerez/spotify-web-api-js) and an implicit grant flow for authorization. Using the examples I got to the point of accessing users and their playlists and I was able to add one extra scope (playlist-read-private) to the scopes. I am trying to add the other ones I need (like playlist-modify-public) but it isn't working. Rather than authorizing (or going to the redirect URL) it will throw an XMLHttpRequest error of 401: Unauthorized. The error description is error_description=Illegal+scope:+playlist-modify-public. The first time I added a new scope, it wouldn't work. I took a break, returned to my code and re-tried exactly the same thing and it suddenly worked (with a pop-up for a new authorization).

This is the authorization code:

      document.getElementById('login-button').addEventListener('click', function() {

        var client_id = '03ffe0cac0a0401aa6673c3cf6d02ced'; // Your client id
        var redirect_uri = 'http://localhost:8888/'; // Your redirect uri

        var state = generateRandomString(16);

        localStorage.setItem(stateKey, state);
        var scope = 'playlist-read-private user-read-private user-read-email';

        var url = 'https://accounts.spotify.com/authorize';
        url += '?response_type=token';
        url += '&client_id=' + encodeURIComponent(client_id);
        url += '&scope=' + encodeURIComponent(scope);
        url += '&redirect_uri=' + encodeURIComponent(redirect_uri);
        url += '&state=' + encodeURIComponent(state);

        window.location = url;
        // onAuthorize();
      }, false);

In order to add a new scope what I am trying to do is just change

'playlist-read-private user-read-private user-read-email'

to

'playlist-read-private playlist-modify-private user-read-private user-read-email'

Everything works with the first one, but as soon as I change it, the app breaks in the way I described above.

Any ideas how to make the app accept the other scopes so I can actually modify the playlists would be much appreciated. Let me know if I can clarify anything and thank you so much!

(All the code can be found here but I am at a hackathon so it might change quickly)

TL;DR: how can I add a new scope when I use the Spotify API?

Thank you!

2016rshah
  • 651
  • 6
  • 19
  • I have just tried your app and it does work when adding `playlist-modify-private`. – José M. Pérez Oct 12 '14 at 17:53
  • 1
    Yeah I fixed it sometime last night. I'm not sure what was wrong though so I will leave the question open in case somebody else figures it out. Thank you! – 2016rshah Oct 12 '14 at 19:13
  • 1
    I'm also unable to recreate this issue unfortunately. Tried approving a small set of scopes, and then expanding with a few other scopes, no issues. Let us know (comment on this thread, for example) if you experience these problems again. – Michael Thelin Oct 12 '14 at 20:10

0 Answers0