【问题标题】:Spotify public search APISpotify 公共搜索 API
【发布时间】:2018-10-27 21:13:27
【问题描述】:

我曾经有一个使用 Spotify API 搜索艺术家/曲目的应用。 请求很简单, 带有例如此 URL 的获取请求 -

https://api.spotify.com/v1/search?query=bob&type=artist&market=us&limit=50&offset=0

现在看来我还需要在标头中发送一个令牌,为了获得一个令牌,我需要将最终用户连接(或注册)到 Spotify。

API 流程是否发生了变化?

我不能再进行简单的公共 API 调用来搜索曲目或艺术家?

另外,我在 Spotify 文档中看到,如果在查询字符串中提供了 market=from_token,则需要授权。 否则,可选。

【问题讨论】:

    标签: api spotify


    【解决方案1】:

    对 Spotify API 的所有请求都必须提供访问令牌。令牌不需要附加到用户,您可以使用Client Credentials Flow 代表您的 oauth 客户端生成访问令牌,而不是让用户参与。

    您能否告诉我您在哪里看到标记为可选的授权标头?我想解决这个问题。

    最好的,

    Spotify 开发者支持

    【讨论】:

    【解决方案2】:

    我知道现在回答这个问题为时已晚。 是的,您需要获取 access_token 并将其与您的搜索 url 一起传递以获得结果。尝试如下获取Spotify access_token,

    func callToken() {
            let parameters = ["client_id" : "your client id",// u get in developer account in Spotify.
                              "client_secret" : "ur secret id",
                              "grant_type" : "client_credentials"]
            Alamofire.request("https://accounts.spotify.com/api/token", method: .post, parameters: parameters).responseJSON(completionHandler: {
                response in
                print(response)
                print(response.result)
                print(response.result.value)
                if let result = response.result.value {
                    let jsonData = result as! NSDictionary
                    let token = jsonData.value(forKey: "access_token") as? String
                    print(token!)
                  }
        })
        }  
    

    然后保存该令牌并调用您的搜索网址,如

    search url = "https://api.spotify.com/v1/search?q=Linkin+Park&type=track&limit=5&access_token=\(token)"    // pass the token in this string thats it..
    

    只需通过 youtube 上的在线教程:- https://www.youtube.com/watch?v=KLsP7oThgHU&t=1s 了解 2019 年的最新版本。

    使用 Spotify 集成 + 搜索选项 + 默认 Spotify 网址下载完整的源代码,并获取当前用户的播放列表并在我们的原生 iOS 应用程序中播放:- https://github.com/azeemohd786/Spotify-Demo

    【讨论】:

      猜你喜欢
      • 2015-04-22
      • 1970-01-01
      • 2021-11-04
      • 2018-09-09
      • 1970-01-01
      • 2018-06-12
      • 2015-11-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多