我正在关注 Spotify 的 client credentials authorization flow ,但我所有的curl请求都返回{"error":"invalid_client"}
每一次。以下是 Spotify 的说明:
The request will include parameters in the request body:
- grant_type - Set to “client_credentials”.
The header of this POST request must contain the following parameter:
- Authorization - A Base 64 encoded string that contains the client ID and client secret key. The field must have the format:
Authorization: Basic <base64 encoded client_id:client_secret>
它们还包括一个curl请求的示例:
$ curl -H "Authorization: Basic ZjM4ZjAw...WY0MzE=" -d grant_type=client_credentials https://accounts.spotify.com/api/token
按照他们的示例,到目前为止,我已经尝试过使用以下命令进行 curl 请求:
- client_id 和 client_secret 纯文本
- 两者都是单独编码的
- 仅使用其中之一进行编码
- 两者都编码为带冒号的一个字符串
- 两者都编码为一个字符串,不带冒号
- 上述每一项都带有重新生成的客户端 key
我正在使用 Ruby 的 Base64#encode64
方法进行编码。还是没有运气。有什么有用的提示吗?
最佳答案
好的,我开始工作了 - 将我的 client_id 和 client_secret(用冒号分隔)传递给 Base64.strict_encode64
(不是 Base64.encode64
),然后将其传递给上面的curl请求得到带有访问 token 的200响应。显然 encode64
还不够。
关于ruby - 使用 Spotify 客户端 ID 和 secret 返回无效客户端的 Curl 发布请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39423464/