【发布时间】: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