Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

Invalid scope - Recently played

Solved!

Invalid scope - Recently played

Plan

Premium

Country

United Kingdom

 

Device

Windows laptop

Operating System

Windows 11

 

My Question or Issue

I have been developing an alternative UI for Spotify to play with locally. I want to try and recreate some of the landing/home page and so I wanted to look at getting the recently played tracks by querying https://api.spotify.com/v1/me/player/recently-played

However when I add user-read-recently-played to my scopes in my code, I reauthenticate with Spotify from my app, but I get an error screen, if I look at the Dev Tools the network respose shows `INVALID_SCOPE: Invalid scope` if I take that scope away it all works.

 

Is there a restriction to the scopes we can use during development?

Reply

Accepted Solutions
Marked as solution

Hey Ximzend,

 

I feel such a n00b! I just looked at the URL that was being put into the address bar when my login request is made and it was converting %20 to %2520 (encoded % and then 20. I changed my env string to have spaces instead of %20's and it seems to work now!! It seems strange as that used to work but looks like I have sorted it now though.

 

Thank you for your help though

 

Stefan

View solution in original post

6 Replies

Hi Stefan, welcome to the Community!

Can you please provide some code of where you assign the scope(s) and make the request?

Cheers,

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Hi @Ximzend

 

Sorry for the delay in getting back to you, I didn't get any notification to say the item had had a reply.

 

Sure, I have the scopes set in a .env file as such:

`SPOTIFY_AUTH_SCOPES = streaming%20user-read-email%20user-library-read%20user-library-modify%20user-read-playback-state%20user-modify-playback-state%20user-read-private%20playlist-read-private%20playlist-read-collaborative%20playlist-modify-private%20playlist-modify-public%20user-read-recently-played`

 

I then run the following in my Node app:

```

app.get("/login", (req, res) => {
const state = generateRandomString(16);
res.cookie(stateKey, state);

const scope = process.env.SPOTIFY_AUTH_SCOPES;

const queryParams = querystring.stringify({
client_id: process.env.SPOTIFY_CLIENT_ID,
response_type: "code",
redirect_uri: process.env.SPOTIFY_REDIRECT_URI,
state: state,
scope: scope,
});
res.redirect(`https://accounts.spotify.com/authorize?${queryParams}`);
});

```

 

Without user-read-recently-played on the end (or anywhere in the string) I can successfully authenticate, but as soon as I add it in I get an error

Hi Stefan,

That's really weird. That scope works on my end.

I'll tag this as a possible bug, and hope a Spotify employee looks into this.

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.
Marked as solution

Hey Ximzend,

 

I feel such a n00b! I just looked at the URL that was being put into the address bar when my login request is made and it was converting %20 to %2520 (encoded % and then 20. I changed my env string to have spaces instead of %20's and it seems to work now!! It seems strange as that used to work but looks like I have sorted it now though.

 

Thank you for your help though

 

Stefan

Hi Stefan, Glad you finally figured out the issue above. Apologies, I wanted to ask something slightly different from the issue above but a tad similar to what you're using the web API for. I am trying to get the user-read-recently-played as well but anytime I request the data I get a 504 gateway timeout error. The strange thing about it all is that after a couple of browser refreshes and multiple requests, the data finally comes. I would like to know if you experienced any 504 errors and if not, how you were able to get the user recently played. 

Again, I know my reply is slightly different from the issue above, but I could do with some assistance regarding something similar you built. Appreciate!

 

Hey, my own project has been on hold for a bit so I haven't tested it fully. I dont recall seeing 504's in Postman though. Sorry I can't be of more help, you might find it better to ask in a new post as it might not show here with this being solved already 

Suggested posts

Let's introduce ourselves!

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โ€ฆ

ModeratorStaff / Moderator/ 4 years ago  in Social & Random