Ces*_*son 5 python authentication oauth spotify spotipy
当我尝试在 Spotipy 中运行 cretin 模块时,我收到客户端范围不足的错误消息。Spotify 给出 403 客户端错误,提示“未提供令牌”
尝试了多个模块,只有少数工作,例如 current_user() 模块,但其他模块却吐出客户端范围不足的错误。
尝试了多个模块,只有少数工作,例如 current_user() 模块,但其他模块却吐出客户端范围不足的错误。
import spotipy
import os
import json
import sys
import webbrowser
import spotipy.util as util
from json.decoder import JSONDecodeError
username = sys.argv[0]
try:
token = util.prompt_for_user_token(username)
except:
os.remove(f".cache-{username}")
token = util.prompt_for_user_token(username)
spotify = spotipy.Spotify(auth=token)
albums = spotify.current_user_saved_albums(limit= 100, offset = 0)
userplaylist = spotify.current_user_playlists()
spuser= spotify.current_user()
class spotifyUser:
def __init__(self, userid, followers, playlist):
self.userid = userid
self.followers = followers
self.playlist = playlist
self.albums
#list all user playlists
def all_playlists(playlist):
for r in range(len(playlist['items'])):
print(playlist['items'][r]['name'])
currentuser = spotifyUser(spuser['display_name'],spuser['followers']
['total'], userplaylist)
#all_playlists(currentuser.playlist)
print(albums)
Run Code Online (Sandbox Code Playgroud)
运行结果为:
Traceback (most recent call last):
File "C:\Users\cesse\PycharmProjects\Spotipy\venv\lib\site-packages\spotipy\client.py", line 119, in _internal_call
r.raise_for_status()
File "C:\Users\cesse\PycharmProjects\Spotipy\venv\lib\site-packages\requests\models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.spotify.com/v1/me/albums?limit=100&offset=0
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Python37/codes/Testspotipy.py", line 20, in <module>
albums = spotify.current_user_saved_albums(limit= 100, offset = 0)
File "C:\Users\cesse\PycharmProjects\Spotipy\venv\lib\site-packages\spotipy\client.py", line 585, in current_user_saved_albums
return self._get('me/albums', limit=limit, offset=offset)
File "C:\Users\cesse\PycharmProjects\Spotipy\venv\lib\site-packages\spotipy\client.py", line 146, in _get
return self._internal_call('GET', url, payload, kwargs)
File "C:\Users\cesse\PycharmProjects\Spotipy\venv\lib\site-packages\spotipy\client.py", line 124, in _internal_call
headers=r.headers)
spotipy.client.SpotifyException: http status: 403, code:-1 - https://api.spotify.com/v1/me/albums?limit=100&offset=0:
Insufficient client scope
Run Code Online (Sandbox Code Playgroud)
将额外的参数传递到令牌调用的提示中,范围为以空格分隔的字符串:
token = util.prompt_for_user_token(username, scope="user-library-read <etc>")
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12560 次 |
最近记录: |