Skip to content

Error: Bad or expired token #27

@sspenst

Description

@sspenst

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,
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions