客户端范围不足 – Spotify API Golang

huangapple go评论82阅读模式
英文:

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))

huangapple
  • 本文由 发表于 2022年11月20日 02:01:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/74502378.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定