JohnnyCrazy / SpotifyAPI-NET

:sound: A Client for the Spotify Web API, written in C#/.NET
http://johnnycrazy.github.io/SpotifyAPI-NET/
MIT License
1.47k stars 297 forks source link

Create Playlist Fails #953

Closed jceddy closed 3 months ago

jceddy commented 3 months ago

When I attempt to create a playlist using SpotifyClient, like this:

  var createRequest = new PlaylistCreateRequest(shuffledPlaylistName)
  {
      Collaborative = false,
      Description = "A very descriptive description.",
      Public = true
  };
  outputPlaylist = await spotify.Playlists.Create(user.Id, createRequest);

I get an APIException -- APIException: Insufficient client scope

My understanding is that the required scope is PlaylistModifyPublic, which I have set up in my app's Startup ConfigureServices code:

  services
    .AddAuthentication(options =>
    {
        options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    })
    .AddCookie(options =>
    {
        options.ExpireTimeSpan = TimeSpan.FromMinutes(50);
    })
    .AddSpotify(options =>
    {
        options.ClientId = "<client-id>";
        options.ClientSecret = "<client-secret>";
        options.CallbackPath = "/Auth/callback";
        options.SaveTokens = true;

        var scopes = new List<string> {
          UserReadEmail, UserReadPrivate, PlaylistReadPrivate, PlaylistReadCollaborative, PlaylistModifyPrivate, PlaylistModifyPublic
        };
        options.Scope.Add(string.Join(",", scopes));
    });

Any idea what I might be missing?

jceddy commented 3 months ago

I also tried changing

options.Scope.Add(string.Join(",", scopes));

to

scopes.ForEach(s => options.Scope.Add(s));

In Startup. (Which didn't work.)

jceddy commented 3 months ago

I got it...had to force it to re-authenticate with Spotify after adding the Scopes.