Spotify Activity

Spotify Activity API tracks and displays real-time Spotify music activities, including track details, album covers, and playback status.

Installation

Run the following command to add the package to your project

npm install vibe-activity

1. Basic Usage

Add the package to your project and start fetching your Spotify activity.

const VibeActivity = require('vibe-activity');
 
const spotify = new VibeActivity('CLIENT_ID', 'CLIENT_SECRET', 'REFRESH_TOKEN');
 
spotify.fetchCurrentActivity().then(activity => {
    console.log(activity);
});

2. Reference

SpotifyActivity

The main class used to fetch Spotify activities.

Required Information

  • clientId: Client ID obtained from the Spotify Developer Dashboard.
  • clientSecret: Client Secret obtained from the Spotify Developer Dashboard.
  • refreshToken: Refresh Token obtained through the Spotify OAuth process.

fetchAccessToken()

Fetches a new access token for the Spotify API.

fetchCurrentActivity()

Returns the currently playing Spotify activity. Example output:

{
    "item": {
        "name": "Song Name",
        "artists": [{ "name": "Artist Name" }],
        "album": {
            "name": "Album Name",
            "images": [{ "url": "https://image.url" }]
        }
    }
}

3. Using the Data

DataDescription
activity.item.nameCurrently playing song title
activity.item.artistsList of artists performing the song (array)
activity.item.artists[0].nameFirst artist's name
activity.item.album.nameAlbum name of the song
activity.item.album.imagesList of album cover images (array)
activity.item.album.images[0].urlURL of the album cover image
activity.item.external_urls.spotifySpotify link of the song

Displaying Song Information

You can display the song name, artist name and album art using the fetched data:

const activity = await spotify.fetchCurrentActivity();
 
console.log(`Currently playing: ${activity.item.name} - ${activity.item.artists[0].name}`);
console.log(`Album: ${activity.item.album.name}`);
console.log(`Album Image: ${activity.item.album.images[0].url}`);

Album Image

<img src=${activity.item.album.images[0].url} alt=${activity.item.album.name} />

FAQ

How to Get a Refresh Token?

To obtain a refresh token, you need to complete the Spotify OAuth process. For details, check the Spotify OAuth Guide.

Is There an API Limit?

Yes, the Spotify API has certain rate limits. For details, check the Spotify API Documentation.