Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Bad or expired token #111

Open
strenkml opened this issue Apr 3, 2024 · 2 comments
Open

Error: Bad or expired token #111

strenkml opened this issue Apr 3, 2024 · 2 comments

Comments

@strenkml
Copy link

strenkml commented Apr 3, 2024

I am making a Discord bot that creates playlists from song links that are post in a Discord channel. I am running into the following error:
Error: Bad or expired token. This can happen if the user revoked a token or the access token has expired. You should re-authenticate the user. In the docs it says to use the client credentials if you are making a server side application.

This is the relevant code:

try {
  this.sdk = SpotifyApi.withClientCredentials(this.clientId, this.clientSecret, [
          "playlist-modify-public",
          "user-library-read",
          "playlist-modify-private",
          "user-read-private",
          "user-read-email",
        ]);
} catch (error) {
  console.error(error);
}

const profile = await this.sdk?.currentUser?.profile();

The authentication part runs without error but the profile part throws the error. If I hardcode my user id and try creating the playlist with the following code I just the same error:

const playlist = await this.sdk?.playlists.createPlaylist(userId, {
  name: name,
  collaborative: false,
  description: description,
  public: false,
});
@iamrgroot
Copy link

I think you have the same as #70 (comment)

@mesrobk
Copy link

mesrobk commented Jun 28, 2024

Client credentials are used for server-side authentication limited to non-user-related functionality; hence the playlist API is being rejected. It would be great to know if this would be allowed in the future from Spotify.

https://developer.spotify.com/documentation/web-api/tutorials/client-credentials-flow
The Client Credentials flow is used in server-to-server authentication. Since this flow does not include authorization, only endpoints that do not access user information can be accessed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants