Spotipy current_user_playlists() 不执行请求

问题描述 投票:0回答:1

我一直在使用spotipy 编写一个小型网络应用程序。一切正常,直到 2 天前停止执行

sp.current_user_playlists()
函数。该请求正在由spotipy 构建并发送,但似乎从未得到答复。其他功能如
playlist_items()
工作得很好。如果我通过 Spotify 文档尝试该 API 端点,我也会得到预期的结果。 没有错误或任何与此相关的事情,网站只是继续加载,服务器似乎什么也没做。

我确信我拥有此端点所需的所有范围,因为它在几天前确实有效。

SpotifyOAuth(client_id=client_id,
                    client_secret=client_secret,
                    redirect_uri=url_for('redirect_page', _external=True),
                    scope='user-read-playback-state user-modify-playback-state user-read-currently-playing '
                          'playlist-read-collaborative, playlist-read-private, user-library-read, '
                          'playlist-modify-private, playlist-modify-public'
                    )

如果有人知道问题可能是什么,我将非常感激!

spotify spotipy
1个回答
0
投票

使用此测试代码

scope
用于获取当前用户的播放列表

playlist-read-private
import spotipy
from spotipy.oauth2 import SpotifyOAuth
import os

# Set your Spotify API credentials as environment variables, it will pick by spotipy API
os.environ["SPOTIPY_CLIENT_ID"] = "<your client ID>"
os.environ["SPOTIPY_CLIENT_SECRET"] = "<your client Secret>"
os.environ["SPOTIPY_REDIRECT_URI"] = "<your App's registered redirect URI>"

# Just this scope good enough to get playlist-read-private API
scope = "playlist-read-private"

# This API call raise web browser and ask user login for getting callback with Authorization Code flow
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))

# After get token, can call real API
user_playlists = sp.current_user_playlists()

# from the result, we picked up the songs track information
for idx, item in enumerate(user_playlists["items"]):
    playlist_name = item["name"]
    print(idx, playlist_name, " – ", item["type"] , item["owner"]["uri"])

结果

enter image description here

您可以通过Spotify网页查看

https://developer.spotify.com/documentation/web-api/reference/get-a-list-of-current-users-playlists

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.