英文:
Insufficient client scope - Spotify API Golang
问题
我想将我拥有的所有曲目放入一个新的播放列表中的一个切片,但是它抛出了一个"Insufficient client scope"错误。这是我的代码,客户端是使用"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...)
}
我在这里看到了Python的可能解决方案链接,但我不知道如何将其翻译成Go的zmb3 API。
英文:
I want to put all the tracks that i have in a slice inside a new playlist but it throws me a Insufficient client scope
error. This is my code and the client is created with 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 have seen the posible solution in Python here but i don't know how to translate this to the Go's API by zmb3
答案1
得分: 0
在查看了GitHub上的更多代码后,我发现问题出在auth
的声明上,我没有添加必要的范围。它应该像这样:
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))
英文:
So after looking at more code in GitHub i found out that the problem was in the declaration of the auth
that i didn't add the neccesaries scopes. It should look something 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))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论