【发布时间】:2022-11-09 00:48:37
【问题描述】:
我正在尝试使用 Spotify 的 Client Credentials Flow 和 Python 获取令牌,但是我只得到以下信息:
{“错误”:“无效客户端”,“错误描述”:“无效客户端”}
我正在关注本指南 - https://developer.spotify.com/documentation/general/guides/authorization/client-credentials/
使用此示例脚本作为起点 - https://www.w3schools.com/python/showpython.asp?filename=demo_requests_post_headers
这是我的代码(我更改了包含客户端 ID 和客户端密钥的 Base 64 编码字符串):
import requests
url = 'https://accounts.spotify.com/api/token'
myobj = {'grant_type': 'client_credentials'}
#use the 'headers' parameter to set the HTTP headers:
x = requests.post(url, data = myobj, headers = {"Authorization": "Basic Base64EncodedStringHere==","Content-Type": "application/x-www-form-urlencoded"})
print(x.text)
如果我将最后一行更改为 print(x),我将得到:<Response [400]>
显然我做错了什么,但我不知道是什么?
【问题讨论】: