【发布时间】:2019-08-14 03:21:56
【问题描述】:
我正在尝试使用 util.prompt_user_for_token() 方法完成 spotipy 身份验证流程 - 我的总体目标只是能够创建用户播放列表。当我运行我的代码时,我被定向到我的重定向 URL 页面,该 URL 现在按预期附加了一个“code=”段。当我尝试在出现提示时将此 URL 复制回该字段时,我总是收到“spotipy.oauth2.SpotifyOauthError: Bad Request”。
最初我将重定向 URL 设置为 https://www.google.ca/,但在阅读了其他一些线程后,我又回到了文档中也提到的“https://example.com/callback/”,但这并没有解决问题。我将不胜感激任何指针!
def authenticate(username):
scope = 'playlist-modify-public'
token = util.prompt_for_user_token(
username=username,
scope=scope,
client_id='',
client_secret='',
redirect_uri='https://example.com/callback/'
)
return token
def createPlaylist(authToken, username):
if authToken:
spotifyObject = spotipy.Spotify(authToken)
spotifyObject.trace = False
spotifyObject.user_playlist_create(spotifyUsername, 'playlistTestName')
else:
print("Can't get token for", username)
return
authToken = authenticate(spotifyUsername)
createPlaylist(authToken, spotifyUsername)
这是我收到的完整错误消息:
Traceback (most recent call last):
File "PlaylistGenerator.py", line 31, in <module>
authToken = authenticate(spotifyUsername)
File "PlaylistGenerator.py", line 15, in authenticate
redirect_uri='https://example.com/callback/'
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotipy/util.py", line 86, in prompt_for_user_token
token_info = sp_oauth.get_access_token(code)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotipy/oauth2.py", line 217, in get_access_token
raise SpotifyOauthError(response.reason)
spotipy.oauth2.SpotifyOauthError: Bad Request
【问题讨论】:
标签: python authentication oauth-2.0 spotify spotipy