我试图通过使用curl命令来使用Spotify API。首先使用Web API,点击搜索,然后输入艺术家姓名。它生成了我应该在命令提示符下运行的curl 命令。
每当我尝试跑步时,它都会给我:
{
"error": {
"status": 401,
"message": "Invalid access token"
}
}
https://developer.spotify.com/documentation/web-api/reference/search 我生成代码的链接。 有人可以帮助我并让我知道我做错了吗?
如果使用Git BASH和jq,curl调用API会更容易。
Spotify 凭证(CLIENT_ID、CLIENT_SECRET)
CLIENT_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
CLIENT_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ACCESS_TOKEN=$(curl -s -X POST 'https://accounts.spotify.com/api/token' -H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET" \
| jq -r '.access_token')
curl --request GET \
--url 'https://api.spotify.com/v1/search?q=remaster%2520track%3ADoxy%2520artist%3AMiles%2520Davis&type=album' \
--header 'Authorization: Bearer '$ACCESS_TOKEN