为基于python-flask的webapp导入的模块要求用户输入



我正在使用Spotipy模块来编写一个web应用程序以生成播放列表。我遇到了一个问题,spottipy提示用户输入一个通过终端重定向到的URL。因为用户只看到烧瓶显示的内容,所以这是不可能的,应用程序也无法进行。

有没有办法对输入的内容进行编码?每次都一样。这些就是问题所在。我已经评论掉了一些旧的东西,正在尝试一些新的东西,但我认为它不会起作用,因为我需要能够创建播放列表

scope = "playlist-modify-public"
redirect_uri = "https://umatt.me/"
#manager = SpotifyOAuth(scope=scope, client_id=CLIENT_ID, client_secret=CLIENT_SECRET, redirect_uri=redirect_uri)
#spotify = spotipy.Spotify(client_credentials_manager=manager)
manager = SpotifyClientCredentials(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)
spotify = spotipy.Spotify(auth_manager=manager)

这些线让我认为这是的问题

Enter the URL you were redirected to: ['Island in The Sun', ' Ms. Jackson', " Day 'N' Nite"]
Enter the URL you were redirected to: ['Island in The Sun', ' Ms. Jackson', " Day 'N' Nite"]
Enter the URL you were redirected to: ['Island in The Sun', ' Ms. Jackson', " Day 'N' Nite"]
Enter the URL you were redirected to: ['Island in The Sun', ' Ms. Jackson', " Day 'N' Nite"]

您使用的是客户端凭据授权流,但这仅用于服务器到服务器的身份验证。如果你想让用户登录,你应该使用授权代码流而不是

import spotipy
from spotipy.oauth2 import SpotifyOAuth
scope = "user-library-read"
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
results = sp.current_user_saved_tracks()
for idx, item in enumerate(results['items']):
track = item['track']
print(idx, track['artists'][0]['name'], " – ", track['name'])

最新更新