[][src]Crate rspotify


Rspotify is a lightweight wrapper for the Spotify Web API It includes helper functions for all Spotify's endpoints, such as fetching metadata (search and look-up of albums, artists, tracks, playlists, new releases) and user's information (follow users, artists and playlists, and saved tracks management).


rspotify supports all of the features of the Spotify Web API including access to all end points, and support for user authorization, notes that before accessing to any end points, you need to be authorized. For details on the capabilities you are encouraged to review the Spotify Web Endpoint Reference documentation

Getting Started


Since all methods require user authorization now, you will need to generate an authorization token that indicates that the user has granted permission for your application to perform the given task. You will need to register your app to get the credentials necessary to make authorized calls.

Even if your script does not have an accessible URL you need to specify one when registering your application where the spotify authentication API will redirect to after successful login. The URL doesn't need to work or be accessible, you can specify "http://localhost/", after successful login you just need to copy the "http://localhost/?code=..." URL from your browser and paste it to the console where your application is running.


If you have a use case you are intertested in, you could check the examples, which has all kinds of detailed examples. For example, If you want to get recently played history, you could check current_user_recently_played. This is the example code:

extern crate rspotify;

use rspotify::client::Spotify;
use rspotify::util::get_token;
use rspotify::oauth2::{SpotifyClientCredentials, SpotifyOAuth};

async fn main() {
// Set client_id and client_secret in .env file or
// export CLIENT_ID="your client_id"
// export CLIENT_SECRET="secret"
// export REDIRECT_URI=your-direct-uri

// Or set client_id, client_secret,redirect_uri explictly
// let oauth = SpotifyOAuth::default()
//     .client_id("this-is-my-client-id")
//     .client_secret("this-is-my-client-secret")
//     .redirect_uri("http://localhost:8888/callback")
//     .build();

let mut oauth = SpotifyOAuth::default()
match get_token(&mut oauth).await {
Some(token_info) => {
let client_credential = SpotifyClientCredentials::default()
// Or set client_id and client_secret explictly
// let client_credential = SpotifyClientCredentials::default()
//     .client_id("this-is-my-client-id")
//     .client_secret("this-is-my-client-secret")
//     .build();
let spotify = Spotify::default()
let history = spotify.current_user_recently_played(10).await;
println!("{:?}", history);
None => println!("auth failed"),



Client to Spotify API endpoint


All Spotify API endpoint response object


The module contains function about authorization and client-credential


All enums for rspotify


utils function