我可以从spotify API保存哪些数据?
我正在建立一个网站,并将SpotifyAPI用作音乐库。我想添加更多的过滤器和顺序选项来搜索traks,这比api允许的要多,所以我想知道我可以从api将哪些曲目/歌曲数据保存到我的DB中,比如艺术家姓名或人气 我想保存:姓名、艺术家、专辑和其他一些东西。这是可能的还是违反了条款和条件 提前谢谢 是的,这是可能的 数据存储在端点的Spotify API中我可以从spotify API保存哪些数据?,api,web,spotify,libspotify,Api,Web,Spotify,Libspotify,我正在建立一个网站,并将SpotifyAPI用作音乐库。我想添加更多的过滤器和顺序选项来搜索traks,这比api允许的要多,所以我想知道我可以从api将哪些曲目/歌曲数据保存到我的DB中,比如艺术家姓名或人气 我想保存:姓名、艺术家、专辑和其他一些东西。这是可能的还是违反了条款和条件 提前谢谢 是的,这是可能的 数据存储在端点的Spotify API中 import requests """ Import library in order to make api calls.
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()
每个端点处理客户机(您)请求的特定类型的数据
我给你举个例子。相同的逻辑适用于所有其他端点
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提供了什么。如果你想要答案,请更具体地说明你在寻找什么样的数据。当然,我会编辑帖子谢谢你的回答,但我想知道条款和条件。他们允许你保存他们的数据吗?这很有帮助。我查看了文档,没有看到任何明确阻止我保存数据的内容。我确实读过几次,如果用户撤销访问,您应该清理数据。虽然我认为一定有某种限制,但我还是犹豫不决。我的用例是保存我为用户生成的播放列表上的信息,这样我就知道不要添加以前添加的歌曲,并限制API调用。