Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

spotify-connect

Package Overview
Dependencies
Maintainers
0
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spotify-connect

Get useful analytics from the spotify API in your React app

  • 1.7.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
0
Weekly downloads
 
Created
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

  • Get currently playing track: Retrieve information about the track currently being played by a Spotify user.

    • Endpoint: https://api.spotify.com/v1/me/player/currently-playing
  • Get recently played tracks: Retrieve the list of recently played tracks of a Spotify user.

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

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

Keywords

FAQs

Package last updated on 19 Sep 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc