【问题标题】:Golang - spotify : This request requires user authenticationGolang - spotify:此请求需要用户身份验证
【发布时间】:2021-12-26 08:35:50
【问题描述】:

我正在编写一个机器人,它采用音乐和艺术家的名称并将其添加到带有zmb3 Spotify library 的选定播放列表中。除了将音乐添加到播放列表部分之外,一切正常;

机器人给了我这个错误:this request requires user authentication. 但 Spotify 令牌和 Spotify 秘密是有效的。

我搜索了,但我没有得到任何东西。 还有什么比 Spotify Token 和 Spotify Secret 更需要的吗? 我该怎么办?

代码:

// create spotify client connection and context to connect spotify
    client, ctx := api.SpotifyConnection(SPOTIFYTOKEN, SPOTIFYSECRET)

    // add playlist
    playlist, err := client.GetPlaylist(ctx, PLAYLISTID)
    if err != nil {
        log.Fatal(err.Error())
    }

/* SOME CODES */

if results.Tracks != nil {
            items := results.Tracks.Tracks
            musicID := items[0].ID.String()
            cmd.AddMusic(client, ctx, playlist.ID.String(), musicID)

错误:

2021/12/26 11:06:25 This request requires user authentication.

【问题讨论】:

    标签: go spotify spotify-app


    【解决方案1】:

    这样看 - 您可以在未登录帐户的情况下将曲目添加到播放列表吗?您的代码也是如此。使用TOKENSECRET_KEY 对API 进行身份验证不是问题,但您需要引入用户身份验证,以便用户在打开您的应用时登录并可以将曲目添加到自己的播放列表中。

    zmb3 README 中有一个 Authentication 部分应该会有所帮助:

    您可以使用客户端凭据流进行身份验证,但这不提供访问用户私人数据的任何授权。对于大多数用例,您需要使用授权代码流。这个包包含一个 Authenticator 类型来为你处理细节。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-30
      • 2017-05-17
      • 2017-09-14
      • 1970-01-01
      • 2017-01-30
      相关资源
      最近更新 更多