Type in your question below and we'll check to see what answers we can find...
Loading article...
Submitting...
If you couldn't find any answers in the previous step then we need to post your question in the community and wait for someone to respond. You'll be notified when that happens.
Simply add some detail to your question and refine the title if needed, choose the relevant category, then post.
Before we can post your question we need you to quickly make an account (or sign in if you already have one).
Don't worry - it's quick and painless! Just click below, and once you're logged in we'll bring you right back here and post your question. We'll remember what you've already typed in so you won't have to do it again.
Please see below the most popular frequently asked questions.
Loading article...
Loading faqs...
Please see below the current ongoing issues which are under investigation.
Loading issue...
Loading ongoing issues...
Plan
Free/Premium
Country
Germany
Operating System
Windows 10
My Question or Issue
Hello everyone,
I have a small issue again 🙂 When I make API requests to perform certain actions (such as adding songs to the queue, pausing/resuming playback, setting volume, or skipping songs).
(I'm using the Authorization Code flow.)
The way I generate the Code:
[URL] https://accounts.spotify.com/de/authorize?response_type=token&client_id=..&scope=user-read-currently...
The way I generate/refresh Tokens:
const requestBody = new URLSearchParams();
requestBody.append('grant_type', 'authorization_code');
requestBody.append('code', Code);
requestBody.append('redirect_uri', 'http://localhost');
requestBody.append('client_id', SpoClientID);
requestBody.append('client_secret', SpoClientSecret);
try {
const response = await axios.post(TOKENendpoint, requestBody, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
});
Refreshing Tokens:
axios.post(TOKENendpoint, null, {
params: {
grant_type: 'refresh_token',
refresh_token: `${SpotifyRefreshToken}`
},
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: `Basic ${authString}`
},
})
I'm grateful for any help. Have a wonderful day and stay healthy 🙂
Solved! Go to Solution.
I recommend you to generate a new access token, and not a refreshed one.
You need to add the user-modify-playback-state scope to control playback, as you can read on the respective documentation pages under Authorization scopes:
https://developer.spotify.com/documentation/web-api/reference/add-to-queue
https://developer.spotify.com/documentation/web-api/reference/start-a-users-playback
https://developer.spotify.com/documentation/web-api/reference/set-volume-for-users-playback
https://developer.spotify.com/documentation/web-api/reference/skip-users-playback-to-next-track
P.S. you need to have a Premium subscription to use most or all of the Player scopes.
HUH I was sure I already answered.. sorry!
Yeah I know that and I did it, thats why Im so confused about getting error 401.
Thats the answer I get to the token request, there you can also see the scopes. (And I got Spotify Premium 🙂 )
{
access_token: 'BQAsNIZg1...6SYTiE',
token_type: 'Bearer',
expires_in: 3600,
scope: 'user-modify-playback-state user-read-playback-state user-read-currently-playing'
}
Okay. Error 401 means the token is expired. Have you tried getting a new one?
(I didn't see that scope in your posted URL, but never mind than.)
Yeah, I automatically generate new tokens if the code starts or if the old one expires.
And the error says its invaild and not expired,
status: 401,
statusText: 'Unauthorized',
headers: Object [AxiosHeaders] {
'www-authenticate': 'Bearer realm="spotify", error="invalid_token", error_description="Invalid access token"',
Oh and yeah sorry, I shared the wrong link to you 🙈
Edit: Here the link I actually use: https://accounts.spotify.com/de/authorize?response_type=code&client_id=..&scope=user-read-currently-...
Then I don't know why it doesn't work for you.
Thats sad haha Idk, if I test it in the dev docs (as Example set volume) it works..
But the Code looks fine, right?
I recommend you to generate a new access token, and not a refreshed one.
I ll try it later and let you know if it worked. Have a nice day and thank you for the help 🙂
Got still the same problem... And still no Idea what Im doing wrong.. But if I try it at Dev Docs it still works...
{
access_token: 'BQCqpZMghX0mxPEDdC1smFDqfv...TDFQQW9s3nkpBE3qRrcQjqOUjcHv8qOn4QQUKUahEA-yINtVT5rYergy3P0T47GDDgNiP6NzwENUq6ZzxTSjlUxWgspXWEAMoJXWGI_V9GP0y4F8xvcD0nPpG0znlIoZuQ9M4ogCVe',
token_type: 'Bearer',
expires_in: 3600,
refresh_token: 'AQBhAjMzKyfEH3jWCXtXJu...L-_QJvUOURjyQmdMTrW-8UJ_VPmtJUouoRWLB41R8BFiIQN_IHh5bFD0U',
scope: 'user-modify-playback-state user-read-currently-playing'
}
The POST request:
Yoo, just fixed it for add Song, I gave the Headers in the Data object 🙈 Volume still don't works, idk why, but I ll find it out. So thank you again for the help and have nice days!
*edit: Everything works now, tysm 🙂
Hi!
This has to do with the 'scopes', when you create the token you must set the rules for that token, as the documentation mentions here.
https://developer.spotify.com/documentation/web-api/tutorials/code-flow
Por example:
var scopes = "user-read-private user-read-email ugc-image-upload user-read-playback-state user-modify-playback-state user-read-currently-playing playlist-read-private playlist-read-collaborative user-read-recently-played";
var client_ID = '2524'
const dev =
`https://accounts.spotify.com/authorize?client_id=`+client_ID+`&response_type=code&redirect_uri=http://localhost:3000/login&scope=` +
scopes;
Hey there you, Yeah, you! 😁 Welcome - we're glad you joined the Spotify Community! While you here, let's have a fun game and get…