Socket
Socket
Sign inDemoInstall

spotify-connect

Package Overview
Dependencies
31
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    spotify-connect

Get useful analytics from the spotify API in your React app


Version published
Weekly downloads
3
Maintainers
1
Install size
5.69 MB
Created
Weekly downloads
 

Readme

Source

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

  • Currently Playing Track API: Retrieve information about the track currently being played by a Spotify user.
    • Endpoint: https://api.spotify.com/v1/me/player/currently-playing

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

Keywords

FAQs

Last updated on 28 Nov 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc