api - 我可以从 Spotify API 保存哪些数据?

标签 api web spotify libspotify

我正在构建一个网站,并使用 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 条款才能将其公开。

旁注:Spotipy docs.

关于api - 我可以从 Spotify API 保存哪些数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49922421/

相关文章:

python - 将 web api 数据转换为 python DataFrame

windows - win32自定义内存管理有什么限制?

javascript - 加载数据时读取缓冲区

javascript - 禁止更新连接到 redux 状态的子组件

javascript - Spotify 网络 API 结果 "undefined"

python - 使用 Spotipy 获取当前正在播放的歌曲会出现错误 : "' Spotify' object has no attribute 'currently_playing' "

api - 如何使用 echonest api 获取特定歌曲的 Spotify ID

api - Microsoft SkyDrive 是否有 API?

php - 将 Azure Microsoft Translator API 与 PHP 和 cURL 结合使用

java - 玩!框架-向后兼容性