Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
Spotify API Error. 401 Permissions missing. When Attempting to Play Track

I am trying to play a track on my app using spotify-web-api-node

  const playSong = async () => {
    // Verify access token with
    console.log(spotifyApi.getAccessToken())

    setCurrentTrackId(track.track.id);
    setIsPlaying(true);
    spotifyApi
      .play({
        uris: [track.track.uri],
      })
      .then((d) => console.log("hi", d))
      .catch((e) => console.log("err", e));
  };

https://github.com/caseysiebel/spotify-clone/blob/main/components/Song.tsx#L19

When I fire off this call to spotifyApi.play(), I am getting this error back WebapiRegularError: An error occurred while communicating with Spotify's Web API. Details: Permissions missing. with error code 401.

I have the accessToken and refreshToken set in my app. I am able to log in and get data from the API such as user, playslist and track data. But when I try to play a track, it's says I don't have permission.

I thought this might have something to do with how I've set the scopes in the Spotify API, but they look correct to me.

const scopes = [
  "user-read-email",
  "playlist-read-private",
  "playlist-read-collaborative",
  "user-read-email",
  "streaming",
  "user-read-private",
  "user-library-read",
  "user-top-read",
  // "user-library-modify"
  "user-read-playback-state",
  "user-modify-playback-state",
  "user-read-currently-playing",
  "user-read-recently-played",
  "user-read-playback-state",
  "user-follow-read",
].join(",");

https://github.com/caseysiebel/spotify-clone/blob/main/lib/spotify.ts#L5

It seems like this has something to do with the scopes passed into the authorization LOGIN_URL but the streaming scope is definitely present and I can't see what the issue. It seems this way because certain API request work and others say they don't have permission.

Does anyone see what could be causing this issue with the missing persmisions issue and the Spotify API?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

In lib/spotify.ts line 23 needed to be scope: scopes, not scopes: scopes,.

Actually using type checking probably would have been helpful here.

https://github.com/currenthandle/spotify-clone/commit/736108de1a1a132c43810d8415584f3be198609a#diff-b030a1ce426906990f8ed48fd8be76f54558b94141f4c811e679fef6661d396dR23

about 4 years ago · Juan Pablo Isaza Report

0

I think the problem is with your spotify.js file. Here in clientId are you sure the name NEXT_PUBLICCLIENT_ID is right? Shouldn't it be NEXT_PUBLIC_CLIENT_ID.

    const spotifyApi = new SpotifyWebApi({
      clientId: process.env.NEXT_PUBLICCLIENT_ID,
      clientSecret: process.env.NEXT_PUBLIC_CLIENT_SECERT,
    });

Try and let me know if this work or not?

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!