【发布时间】:2019-05-03 05:14:44
【问题描述】:
这是我向https://accounts.spotify.com/api/token 发出 POST 请求的众多尝试之一。
范围设置为“playlist-modify-public, playlist-modify-private”。
我正在使用 Python 3.7、Django 2.1.3。
无论我做什么,response_data 都会返回 {'error': 'invalid_client'}
我已经尝试了很多事情,包括根据 official Spotify documentation 为这个特定的请求传递请求正文中的 client_id/client_secret ......但无济于事。
请帮忙!
def callback(request):
auth_token = request.GET.get('code') # from the URL after user has clicked accept
code_payload = {
'grant_type': 'authorization_code',
'code': str(auth_token),
'redirect_uri': REDIRECT_URI,
}
auth_str = '{}:{}'.format(CLIENT_ID, CLIENT_SECRET)
b64_auth_str = base64.b64encode(auth_str.encode()).decode()
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic {}'.format(b64_auth_str)
}
post_request = requests.post(SPOTIFY_TOKEN_URL, data=code_payload, headers=headers)
response_data = json.loads(post_request.text)
# ==> {'error': 'invalid_client'}
【问题讨论】:
-
你好。你想好怎么解决了吗?
-
嘿@MatteusBarbosa,我实际上意识到我已经在 Spotify Dashboard 上重置了我的 Spotify client_secret 并且完全忘记了相应地修改我的代码......感觉真的很聪明:|
-
感谢您的回复