无法在Spotify API上跳到下一首歌(通过Spotipy)



我正在使用spotipy实现一个简单的应用程序。
我想跳过下一首曲目,但我在输出中出现此错误:

spotipy.client.SpotifyException: http status: 403, code:-1 - https://api.spotify.com/v1/me/player/next: 对当前用户不可用

我的代码:

import os
import spotipy
import spotipy.util as util
from json.decoder import JSONDecodeError

# Set data client, redirect URL and username
username = 'xxxx'
client_id = 'xxxxxxxx'
client_secret = 'xxxxxxxx'
redirect_uri = 'https://www.xxxxx.it/'
scope = 'user-modify-playback-state'

# Erase cache and prompt for user permission
try:
token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri)
except (AttributeError, JSONDecodeError):
os.remove(f".cache-{username}")
token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri)

# Configure Spotify
sp = spotipy.Spotify(auth=token)
current = sp.next_track()

您只能为高级用户跳过歌曲。
查看以下文章:

  • 跳过用户的播放到下一曲目
  • 使用 Spotify Connect Web API

仅供参考,错误403是授权错误:

HTTP403 Forbidden客户端错误状态响应代码指示 服务器理解请求但拒绝授权。

此状态类似于401,但在这种情况下,重新进行身份验证 不会有什么区别。访问被永久禁止和捆绑 到应用程序逻辑,例如对资源的权限不足。

最新更新