Home >Backend Development >Golang >Insufficient client scope - Spotify API Golang

Insufficient client scope - Spotify API Golang

PHPz
PHPzforward
2024-02-06 10:03:07909browse

客户端范围不足 - Spotify API Golang

Question content

I want to put all the tracks in the slice into a new playlist but it throws me insufficient clientscope mistake. This is my code, the client is created using auth

func copyTracksToPlaylist(filteredTracks []spotify.PlaylistItem, client *spotify.Client, ctx context.Context) error {
   newPlaylistID := os.Getenv("NEW_PLAYLIST_ID")

   filteredSongsIDs := extractTracksIDs(filteredTracks)

   return client.ReplacePlaylistTracks(ctx, spotify.ID(newPlaylistID), filteredSongsIDs...)
}

I saw a possible solution in python here but I don't know how to convert it to go's api via zmb3


Correct answer


so , after looking at more code in github, I found that the problem was in the declaration of auth, where I didn't add the necessary scope. It should look like this:

auth = spotifyauth.New(spotifyauth.WithClientID(os.Getenv("SPOTIFY_ID")), spotifyauth.WithClientSecret(os.Getenv("SPOTIFY_SECRET")), spotifyauth.WithRedirectURL(RedirectUrl), spotifyauth.WithScopes(spotifyauth.ScopeUserReadPrivate, spotifyauth.ScopePlaylistModifyPublic, spotifyauth.ScopePlaylistModifyPrivate, spotifyauth.ScopeUserLibraryRead, spotifyauth.ScopeUserLibraryModify))

The above is the detailed content of Insufficient client scope - Spotify API Golang. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete