Skip to content

aquibbaig/spotify-connect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spotify-connect

Fetch data in real time from Spotify APIs.

This guide demonstrates how to retrieve data from the Spotify API (such as currently playing track) in a react application or server component.

npm i spotify-connect

Currently supported APIs

Requirements

To get started, you'll need the following:

  • client_id: Spotify app client ID
  • client_secret: Spotify app client secret
  • refresh_token: Spotify app refresh token. You can generate one as explained in various articles on the web. Example

Available Response Data Parsing Methods

The response from the Spotify API can be parsed using the following method:

parseCurrentTrack(data)

Returns:
{
  track: {
    id: item.id,
    name: item.name,
    artist: item.artists,
    album: item.album.name,
    image: item.album.images[0].url,
    duration: item.duration_ms,
    progress: progress_ms,
    uri: item.uri,
  },
  timestamp,
}

Usage

  1. In the root of your application or wherever you want to use spotify-connect utilities, import the SpotifyConnectContextProvider.
<SpotifyConnectContextProvider
  clientId={SPOTIFY_CLIENT_ID}
  clientSecret={SPOTIFY_CLIENT_SECRET}
  refreshToken={SPOTIFY_REFRESH_TOKEN}
>
  1. Now you can use the utility in your component. You can configure when to invalidate stale data and refetch.
  const { data } = useCurrentTrack()

  options: {
    refetchInterval: (milliseconds, default = 5000 or 5seconds)
  }

About

Fetch data in real time from Spotify APIs

Resources

Stars

Watchers

Forks

Packages

No packages published