I already figured out the URL is https://spclient.wg.spotify.com/color-lyrics/v2/track/${TRACK_ID}?format=json&vocalRemoval=false
And it requires two headers. app-platform: WebPlayer
and authorization: Bearer TOKEN
.
So using curl I am able to get the lyrics information like that:
$ TRACK_ID=3z8h0TU7ReDPLIbEnYhWZb
$ BEARER_TOKEN=xxxxxxxxxxxxxx
$ curl "https://spclient.wg.spotify.com/color-lyrics/v2/track/${TRACK_ID}?format=json&vocalRemoval=false" -H "app-platform: WebPlayer" -H "authorization: Bearer ${BEARER_TOKEN}"
{
"lyrics": {
"syncType": "LINE_SYNCED",
"lines": [
{
"startTimeMs": "110",
"words": "Is this the real life? Is this just fantasy?",
"syllables": [],
"endTimeMs": "0"
},
{
"startTimeMs": "6990",
"words": "Caught in a landslide, no escape from reality",
"syllables": [],
"endTimeMs": "0"
},
...
The actual question is how do I programmatically get the required bearer token? I've tried a token requested using Get Token button on this site: https://developer.spotify.com/console/get-track/
But that token only appears to work for the official API. For the lyrics API I always get the following response for that token:
{
"error": {
"status": 403,
"message": "Client not allowed"
}
}
Also, the bearer tokens from the link above are way shorter and contain no dashes.
I know I can just copy the Bearer Token that is used by the web client on https://open.spotify.com but the token always expires after a very short amount of time.
So I'm either looking for a manual way to get a permanent token or for a way to programmatically get short-lived tokens.
I'm not looking for a solution in a specific programming language. Any language will do or an abstract explanation.