我有一个运行良好的 python 程序。今天,我注意到有些事情发生了变化。该项目的想法是我可以将 Spotify 上我喜欢的所有歌曲转移到播放列表中。这是代码:
import spotipy
from spotipy.oauth2 import SpotifyOAuth
from app import app
def transfer_tracks(destination_playlist_uri):
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id='id',
client_secret='secret',
redirect_uri='redirect_uri',
scope='user-library-read playlist-modify-public'))
# Retrieve the total count of liked tracks
saved_tracks = sp.current_user_saved_tracks(limit=1)
total_tracks = saved_tracks['total']
# Set the batch size for pagination
batch_size = 20
offset = 0
while offset < total_tracks:
results = sp.current_user_saved_tracks(limit=batch_size, offset=offset)
track_uris = [item['track']['uri'] for item in results['items']]
# Add the track URIs to the destination playlist
destination_playlist_id = destination_playlist_uri.split('/')[-1]
sp.playlist_add_items(destination_playlist_id, track_uris)
offset += batch_size
print("All tracks transferred to the destination playlist!")
# Set the URIs for the destination playlist
destination_playlist_uri = 'https://open.spotify.com/playlist/playlist-id'
# Call the transfer_tracks function
transfer_tracks(destination_playlist_uri)
# Run the Flask server
if __name__ == '__main__':
app.run(port=8080)
这是我遇到的问题:
引发HTTPError(http_error_msg,response=self) requests.exceptions.HTTPError:400 客户端错误:URL 错误请求:https://accounts.spotify.com/api/token
在处理上述异常的过程中,又发生了一个异常:
引发 SpotifyOauthError( Spotipy.oauth2.SpotifyOauthError:错误:无效的客户端,错误描述:无效的客户端
我还尝试在 Spotify Dashboard 上创建另一个应用程序,但没有帮助。我应该做什么,我错过了什么?
我刚刚删除了我的项目所在文件夹中的缓存文件,它有帮助