我正在学习 Python,并尝试使用 Spotify Web api 创建播放列表,但收到 http 400 错误:解析 json 时出错。我想这与令牌中不正确的变量类型有关,但我很难调试它,因为我无法找到一种方法来查看原始格式的发布请求。
通过 API 发布需要授权,这是我为此创建的脚本:
import requests
import base64
requests.packages.urllib3.disable_warnings()
client_id = 'ID'
client_secret = 'SECRET'
redirect_uri = 'http://spotify.com/'
scope = 'playlist-modify-private playlist-read-private'
def request_token():
# 1. Your application requests authorization
auth_url = 'https://accounts.spotify.com/authorize'
payload = {'client_id': client_id, 'response_type':'code','redirect_uri':redirect_uri}
auth = requests.get(auth_url,params = payload)
print '\nPlease go to this url to authorize ', auth.url
# 2. The user is asked to authorize access within the scopes
# 3. The user is …Run Code Online (Sandbox Code Playgroud)