为什么现在不能免费使用Spotify的 Web API了?

人工智能 2026-07-10

我一直在开发一个Python应用,需要调用Spotify API并访问用户的播放列表以及其中的条目。 以下是代码:

import os
import base64
from requests import post, get
import json

clientid = "why would you want to see it"
clientsecret = "no"

def getToken():
    auth_string = clientid + ":" + clientsecret
    auth_bytes = auth_string.encode("utf-8")
    auth_base64 = str(base64.b64encode(auth_bytes), "utf-8")

    url = "https://accounts.spotify.com/api/token"
    headers = {
        "Authorization": "Basic "+auth_base64,
        "Content-Type": "application/x-www-form-urlencoded"
    }
    data = {
        "grant_type": "client_credentials"
    }
    result = post(url, headers=headers, data=data)
    json_result = json.loads(result.content)
    token = json_result["access_token"]
    return token


def get_auth_header(token):
    return {"Authorization": "Bearer "+token}

def get_playlist(token, playlist_id):
    url = "https://api.spotify.com/v1/playlists/"
    headers = get_auth_header(token)
    query_url = url + playlist_id +"/tracks"

    result = get(query_url, headers=headers)
    print(token)
    print(query_url)
    print(result)

token = getToken()
get_playlist(token, "021tegZzZnT8YEpLr0lC3V")

最后一行所引用的播放列表是 这个公开的播放列表.

我甚至尝试使用“search”调用来搜索艺术家,但无论我怎么请求,Spotify都返回403 Forbidden,如果我在请求中使用ThunderClient,它也给出403响应,并说我需要Spotify Premium。

我的仪表板在这里:

一个 Spotify 开发者仪表板,消息为“您的应用因未拥有 Spotify Premium 订阅而被阻止访问 Web API。升级到 Spotify Premium 以访问 Web API 并为您的应用解锁更多功能。”

它说我需要Premium,但是为什么我看到的视频和教程(如这个视频)在没有Premium的情况下也使用API?人们会使用我的程序,但并非每个人都有Premium。

解决方案

“为什么我不能再免费使用Spotify的 Web API?”

因为他们改动了。

据Spotify官方博客文章所述:

“随着时间的推移,自动化和人工智能的进步从根本上改变了开发者访问的使用模式和风险概况,在Spotify目前的规模下,这些风险现在需要更有结构化的控制。

作为回应,我们正在对Spotify for Developers做出改变 以更好地保护创作者、合作伙伴、听众和平台。”

这就是他们的说法。其他的都只是猜测/推断……以及意见。


“… why do the videos and tutorials I see (like this video) use the API without premium?”.

因为它们已经过时!它们以前可能是对的,但现在不再适用。


“People are going to use my program, and not everyone has premium.”

那就太糟糕了。我猜这意味着那些没有Spotify Premium的人将无法使用你的程序。

如果你写的程序依赖于一个免费的API,而该API变成非免费,你就会陷入困境。在编写程序之前,你应该考虑到这种可能性。

记住:

  • “天下没有免费的午餐。”
  • “如果服务是免费的,你就是产品。”

顺便说一句,如果你试图规避这些(新的)Spotify限制,你自己或使用你程序的人很可能在违反Spotify的服务条款。这样做可能会有后果。

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章