登录
首页 >  Golang >  Go问答

Spotify API Golang中的客户端范围不足

来源:stackoverflow

时间:2024-03-03 08:21:17 390浏览 收藏

目前golang学习网上已经有很多关于Golang的文章了,自己在初次阅读这些文章中,也见识到了很多学习思路;那么本文《Spotify API Golang中的客户端范围不足》,也希望能帮助到大家,如果阅读完后真的对你学习Golang有帮助,欢迎动动手指,评论留言并分享~

问题内容

我想将切片中的所有曲目放入新的播放列表中,但它向我抛出 insufficient clientscope 错误。这是我的代码,客户端是使用 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中可能的解决方案,但我不知道如何通过zmb3将其转换为go的api


正确答案


因此,在查看 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))

理论要掌握,实操不能落!以上关于《Spotify API Golang中的客户端范围不足》的详细介绍,大家都掌握了吧!如果想要继续提升自己的能力,那么就来关注golang学习网公众号吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>