pub struct AuthCodeSpotify {
    pub creds: Credentials,
    pub oauth: OAuth,
    pub config: Config,
    pub token: Arc<Mutex<Option<Token>>>,
    /* private fields */
}
Expand description

The Authorization Code Flow client for the Spotify API.

This includes user authorization, and thus has access to endpoints related to user private data, unlike the Client Credentials Flow client. See BaseClient and OAuthClient for the available endpoints.

If you’re developing a CLI application, you might be interested in the cli feature. This brings the Self::prompt_for_token utility to automatically follow the flow steps via user interaction.

Otherwise, these are the steps to be followed to authenticate your app:

  1. Generate a request URL with Self::get_authorize_url.

  2. The user logs in with the request URL. They will be redirected to the given redirect URI, including a code in the URL parameters. This happens on your side.

  3. The code obtained in the previous step is parsed with Self::parse_response_code.

  4. The code is sent to Spotify in order to obtain an access token with Self::request_token.

  5. Finally, this access token can be used internally for the requests. It may expire relatively soon, so it can be refreshed with the refresh token (obtained in the previous step as well) using Self::refresh_token. Otherwise, a new access token may be generated from scratch by repeating these steps, but the advantage of refreshing it is that this doesn’t require the user to log in, and that it’s a simpler procedure.

    See this related example to learn more about refreshing tokens.

There’s a webapp example for more details on how you can implement it for something like a web server, or this one for a CLI use case.

An example of the CLI authentication:

demo

Note: even if your script does not have an accessible URL, you will have to specify a redirect URI. It doesn’t need to work, you can use http://localhost:8888/callback for example, which will also have the code appended like so: http://localhost/?code=....

Fields

creds: Credentialsoauth: OAuthconfig: Configtoken: Arc<Mutex<Option<Token>>>

Implementations

Builds a new AuthCodeSpotify given a pair of client credentials and OAuth information.

Build a new AuthCodeSpotify from an already generated token. Note that once the token expires this will fail to make requests, as the client credentials aren’t known.

Same as Self::new but with an extra parameter to configure the client.

Returns the URL needed to authorize the current client as the first step in the authorization flow.

Trait Implementations

This client has access to the base methods.

Refetch the current access token given a refresh token. May return None if there’s no access/refresh token.

Note that the token is wrapped by a Mutex in order to allow interior mutability. This is required so that the entire client doesn’t have to be mutable (the token is accessed to from every endpoint). Read more

If it’s a relative URL like “me”, the prefix is appended to it. Otherwise, the same URL is returned. Read more

Re-authenticate the client automatically if it’s configured to do so, which uses the refresh token to obtain a new access token. Read more

Refreshes the current access token given a refresh token. The obtained token will be saved internally. Read more

Updates the cache file at the internal cache path. Read more

Sends a request to Spotify for an access token.

Returns a single track given the track’s ID, URI or URL. Read more

Returns a list of tracks given a list of track IDs, URIs, or URLs. Read more

Returns a single artist given the artist’s ID, URI or URL. Read more

Returns a list of artists given the artist IDs, URIs, or URLs. Read more

Get Spotify catalog information about an artist’s albums. Read more

The manually paginated version of Self::artist_albums.

Get Spotify catalog information about an artist’s top 10 tracks by country. Read more

Get Spotify catalog information about artists similar to an identified artist. Similarity is based on analysis of the Spotify community’s listening history. Read more

Returns a single album given the album’s ID, URIs or URL. Read more

Returns a list of albums given the album IDs, URIs, or URLs. Read more

Search for an Item. Get Spotify catalog information about artists, albums, tracks or playlists that match a keyword string. Read more

Get Spotify catalog information about an album’s tracks. Read more

The manually paginated version of Self::album_track.

Gets basic profile information about a Spotify User. Read more

Get full details about Spotify playlist. Read more

Gets playlist of a user. Read more

Check to see if the given users are following the given playlist. Read more

Get Spotify catalog information for a single show identified by its unique Spotify ID. Read more

Get Spotify catalog information for multiple shows based on their Spotify IDs. Read more

Get Spotify catalog information about an show’s episodes. Optional parameters can be used to limit the number of episodes returned. Read more

The manually paginated version of Self::get_shows_episodes.

Get Spotify catalog information for a single episode identified by its unique Spotify ID. Read more

Get Spotify catalog information for multiple episodes based on their Spotify IDs. Read more

Get audio features for a track Read more

Get Audio Features for Several Tracks Read more

Get Audio Analysis for a Track Read more

Get a list of new album releases featured in Spotify Read more

The manually paginated version of Self::categories.

Get a list of playlists in a category in Spotify Read more

The manually paginated version of Self::category_playlists.

Get a list of Spotify featured playlists. Read more

Get a list of new album releases featured in Spotify. Read more

The manually paginated version of Self::new_releases.

Get Recommendations Based on Seeds Read more

Get full details of the items of a playlist owned by a user. Read more

The manually paginated version of Self::playlist_items.

Gets playlists of a user. Read more

The manually paginated version of Self::user_playlists.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

This client includes user authorization, so it has access to the user private endpoints in OAuthClient.

Obtains a user access token given a code, as part of the OAuth authentication. The access token will be saved internally.

Tries to read the cache file’s token. Read more

Parse the response code in the given response url. If the URL cannot be parsed or the code parameter is not present, this will return None. Read more

Tries to open the authorization URL in the user’s browser, and returns the obtained code. Read more

Opens up the authorization URL in the user’s browser so that it can authenticate. It reads from the standard input the redirect URI in order to obtain the access token information. The resulting access token will be saved internally once the operation is successful. Read more

Get current user playlists without required getting his profile. Read more

The manually paginated version of Self::current_user_playlists.

Creates a playlist for a user. Read more

Changes a playlist’s name and/or public/private state. Read more

Unfollows (deletes) a playlist for a user. Read more

Adds items to a playlist. Read more

Replace all items in a playlist Read more

Reorder items in a playlist. Read more

Removes all occurrences of the given items from the given playlist. Read more

Removes specfic occurrences of the given items from the given playlist. Read more

Add the current authenticated user as a follower of a playlist. Read more

Get detailed profile information about the current user. An alias for the ‘current_user’ method. Read more

Get detailed profile information about the current user. An alias for the ‘me’ method. Read more

Get information about the current users currently playing item. Read more

Gets a list of the albums saved in the current authorized user’s “Your Music” library Read more

The manually paginated version of Self::current_user_saved_albums.

Get a list of the songs saved in the current Spotify user’s “Your Music” library. Read more

The manually paginated version of Self::current_user_saved_tracks.

Gets a list of the artists followed by the current authorized user. Read more

Remove one or more tracks from the current user’s “Your Music” library. Read more

Check if one or more tracks is already saved in the current Spotify user’s “Your Music” library. Read more

Save one or more tracks to the current user’s “Your Music” library. Read more

Get the current user’s top artists. Read more

The manually paginated version of Self::current_user_top_artists.

Get the current user’s top tracks. Read more

The manually paginated version of Self::current_user_top_tracks.

Get the current user’s recently played tracks. Read more

Add one or more albums to the current user’s “Your Music” library. Read more

Remove one or more albums from the current user’s “Your Music” library. Read more

Check if one or more albums is already saved in the current Spotify user’s “Your Music” library. Read more

Follow one or more artists. Read more

Unfollow one or more artists. Read more

Check to see if the current user is following one or more artists or other Spotify users. Read more

Follow one or more users. Read more

Unfollow one or more users. Read more

Get a User’s Available Devices Read more

Get Information About The User’s Current Playback Read more

Get the User’s Currently Playing Track Read more

Transfer a User’s Playback. Read more

Start/Resume a User’s Playback. Read more

Start a user’s playback Read more

Pause a User’s Playback. Read more

Resume a User’s Playback. Read more

Skip User’s Playback To Next Track. Read more

Skip User’s Playback To Previous Track. Read more

Seek To Position In Currently Playing Track. Read more

Set Repeat Mode On User’s Playback. Read more

Set Volume For User’s Playback. Read more

Toggle Shuffle For User’s Playback. Read more

Add an item to the end of the user’s playback queue. Read more

Add a show or a list of shows to a user’s library. Read more

Get a list of shows saved in the current Spotify user’s library. Optional parameters can be used to limit the number of shows returned. Read more

The manually paginated version of Self::get_saved_show.

Check if one or more shows is already saved in the current Spotify user’s library. Read more

Delete one or more shows from current Spotify user’s library. Changes to a user’s saved shows may not be visible in other Spotify applications immediately. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.