如何绕过Spotipy提示链接在终端



我正在尝试建立一个网站,使用Spotify python模块向用户显示他们在Spotify上的一些统计数据。我正在使用验证我的应用程序

username = "SomeUsername"
scope = "user-read-playback-state user-modify-playback-state user-top-read user-read-recently-played"
redirect_uri = "http://localhost/"
token = spotipy.util.prompt_for_user_token(
username, scope, CLIENT_ID, CLIENT_SECRET, redirect_uri)
session = spotipy.Spotify(auth=token)

然后打开一个页面,用户在其中授予应用程序访问所需数据的权限,然后将用户重定向到redirect_url。然后在终端中,用户会被提示粘贴他们被定向到的url。这是一个问题,因为我不希望最终用户必须这样做,我甚至不知道他们是否可以。我确信有一个解决方案,但我就是找不到。

我在代码中使用这个:

import spotipy
from spotipy.oauth2 import SpotifyOAuth
# your variables here 
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=SCOPE,client_id=CLIENT_ID,client_secret=CLIENT_SECRET,redirect_uri=REDIRECT_URI))

如果您已经设置了环境变量,您可以简单地使用:

import spotipy
from spotipy.oauth2 import SpotifyOAuth   
SCOPE = 'your-scopes'
spotipy.Spotify(auth_manager=SpotifyOAuth(scope=SCOPE))

最新更新