Python Spotify授权代码流返回不完整的响应
我有一个django服务器,我希望执行spotify授权代码流 以下是我创建的基本框架:Python Spotify授权代码流返回不完整的响应,python,django,oauth,spotify,Python,Django,Oauth,Spotify,我有一个django服务器,我希望执行spotify授权代码流 以下是我创建的基本框架: 用户打开spotify/loginurl SpotifyLoginView将它们重定向到https://accounts.spotify.com/authorizeurl spotify服务器回调到spotify/callback端点 SpotifyCallbackView向https://accounts.spotify.com/api/token获取身份验证令牌 url.py views.py 此
- 用户打开
urlspotify/login
将它们重定向到SpotifyLoginView
urlhttps://accounts.spotify.com/authorize
- spotify服务器回调到
端点spotify/callback
向SpotifyCallbackView
获取身份验证令牌https://accounts.spotify.com/api/token
此外,如果我尝试使用该访问令牌,我会返回一个
401
HTTP错误
$ curl -H "Authorization: Bearer <my acess token>" https://api.spotify.com/v1/me
{
"error" : {
"status" : 401,
"message" : "Unauthorized."
}
}
$curl-H“授权:持票人”https://api.spotify.com/v1/me
{
“错误”:{
“状态”:401,
“消息”:“未经授权。”
}
}
这是怎么回事?在向发出POST请求以获取初始访问令牌时,您必须使用“授权码”作为grant\u type
。在handle\u callback()方法中:
response = requests.post(
"https://accounts.spotify.com/api/token",
data={
"grant_type": "authorization_code",
"code": code,
"redirect_uri": request.build_absolute_uri(
reverse("spotify callback")
),
},
headers=AUTH_HEADER,
)
在向发出POST请求时,您必须使用“授权码”作为grant\u type
,以获取初始访问令牌。在handle\u callback()方法中:
response = requests.post(
"https://accounts.spotify.com/api/token",
data={
"grant_type": "authorization_code",
"code": code,
"redirect_uri": request.build_absolute_uri(
reverse("spotify callback")
),
},
headers=AUTH_HEADER,
)
$ curl -H "Authorization: Bearer <my acess token>" https://api.spotify.com/v1/me
{
"error" : {
"status" : 401,
"message" : "Unauthorized."
}
}
response = requests.post(
"https://accounts.spotify.com/api/token",
data={
"grant_type": "authorization_code",
"code": code,
"redirect_uri": request.build_absolute_uri(
reverse("spotify callback")
),
},
headers=AUTH_HEADER,
)