spotify-connect
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

spotify-connect

Integrate Spotify analytics into your React application to provide real-time analytics. This guide demonstrates how to use the Spotify API to retrieve and parse data on the currently playing track in your React or React Server Components application.

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:

parseCurrentlyPlayingTrack(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 utilities in your components as follows.
  const { data } = useCurrentlyPlaying()

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

Package Sidebar

Install

npm i spotify-connect

Weekly Downloads

1

Version

1.2.0

License

MIT

Unpacked Size

32.2 kB

Total Files

8

Last publish

Collaborators

  • aquibbaig