【问题标题】:How to apply Spotify API authentication on my current code which uses Spotify Search API?如何在我当前使用 Spotify Search API 的代码上应用 Spotify API 身份验证?
【发布时间】:2017-11-09 04:54:52
【问题描述】:

之前我使用的是 Spotify 的搜索 API 没有任何类型的身份验证。但就在上周左右,他们只使用身份验证来使用 API。 因此,过去 2-3 天以来,我一直无法弄清楚此授权如何用于 Search API,作为开发人员,我可以让用户访问来自 Search API 的响应,而无需使用他们的 Spotify 帐户登录。

有人可以帮我解决这个授权问题吗(Spotify 的文档不能解决我的问题:

这是我之前使用的python代码 -

import requests
import json

def Spotify(keyword):

    url = "https://api.spotify.com/v1/search?q="+keyword+"&type=track&limit=1"
    headers = {
    'accept': "application/json",
    'access_token':''
    }


    r = requests.get(url=url,headers=headers).text
    jsonwa = json.loads(r)
    name = jsonwa["tracks"]["items"][0]["name"]
    artists = jsonwa["tracks"]["items"][0]["artists"][0]["name"]
    song_preview_url = jsonwa["tracks"]["items"][0]["preview_url"]
    image = jsonwa["tracks"]["items"][0]["album"]["images"][1]["url"]
    return_this = []
    return_this.append(name)
    return_this.append(artists)
    return_this.append(song_preview_url)
    return_this.append(image)
    print return_this
    return return_this

song = "hello"

Spotify(song)

【问题讨论】:

    标签: python json api python-requests spotify


    【解决方案1】:

    根据web authorization docs

    对 Spotify Web API 的所有请求都需要授权

    您需要您的用户为您的应用授予权限才能获得访问令牌。用户必须登录才能授予权限。

    一旦您的应用被用户授予权限,您就可以从那时起使用refresh_token,并且用户不需要再次授予权限,除非他们撤销权限。您需要管理 access_token 过期时间。

    【讨论】:

      猜你喜欢
      • 2020-07-05
      • 2020-06-18
      • 1970-01-01
      • 2015-02-17
      • 2014-10-30
      • 2022-11-23
      • 2015-03-01
      • 2019-05-13
      • 1970-01-01
      相关资源
      最近更新 更多