我正在构建一个网站,并使用 Spotify API 作为音乐库。我想添加比 API 允许的更多的过滤器和排序选项来搜索 traks,所以我想知道我可以从 API 将哪些轨道/歌曲数据保存到我的数据库中,例如艺术家姓名或流行度。
我想保存:姓名、艺术家、专辑和其他一些内容。这可能吗,还是违反条款和条件?
提前致谢!
最佳答案
是的,这是可能的。
数据存储在端点的 Spotify API 中。
Spotify API endpoint reference here.
每个端点处理客户端(您)请求的特定类型的数据。
我给你举一个例子。相同的逻辑适用于所有其他端点。
import requests
"""
Import library in order to make api calls.
Alternatively, ou can also use a wrapper like "Spotipy"
instead of requesting directely.
"""
# hit desired endpoint
SEARCH_ENDPOINT = 'https://api.spotify.com/v1/search'
# define your call
def search_by_track_and_artist(artist, track):
path = 'token.json' # you need to get a token for this call
# endpoint reference page will provide you with one
# you can store it in a file
with open(path) as t:
token = json.load(t)
# call API with authentication
myparams = {'type': 'track'}
myparams['q'] = "artist:{} track:{}".format(artist,track)
resp = requests.get(SEARCH_ENDPOINT, params=myparams, headers={"Authorization": "Bearer {}".format(token)})
return resp.json()
尝试一下:
search_by_track_and_artist('Radiohead', 'Karma Police')
存储数据并按照您的意愿进行处理。但您必须遵守 Spotify 条款才能将其公开。
关于api - 我可以从 Spotify API 保存哪些数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49922421/