npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

spotify-buddylist

v3.0.0

Published

Fetch the friend activity Spotify feed.

Downloads

11

Readme

spotify-buddylist npm version

Fetch the friend activity Spotify feed.

Note: don't know how to code? Check the extra info at the bottom!

Overview

The Spotify API doesn't include a way to fetch the friend activity feed that's available on the right of the desktop app.

There's an issue on the spotify/web-api repository about that, where a number of people request access to this endpoint since 2015, but it was closed this summer 2020 without any plan to give access to this feature through the official API.

Because I want to fetch this data and I don't like being told no, this repo is a wrapper around the unofficial API that the app calls to fetch the friend activity feed.

Since the calls are pretty trivial, it's mostly there for public documentation purpose rather than to really be used as a library, but I still made it available on npm in case you quickly want to put together something with this.

The only dependency is node-fetch to make HTTP requests.

Usage

To use this API, you need to get a web player access token, not a regular API access token, so you can't use the official API way of logging in, getting and refreshing tokens.

The good news is that if you don't mind logging in on the web player and refreshing a value in your code once a year, it's actually quite easier than the official OAuth way. More on that below.

const buddyList = require('spotify-buddylist')

async function main () {
  const spDcCookie = 'put your cookie here'

  const { accessToken } = await buddyList.getWebAccessToken(spDcCookie)
  const friendActivity = await buddyList.getFriendActivity(accessToken)

  console.log(friendActivity)
}

main()

The output looks like:

{
  "friends": [
    {
      "timestamp": 1600773735000,
      "user": {
        "uri": "spotify:user:shaktirockgym",
        "name": "shaktirockgym"
      },
      "track": {
        "uri": "spotify:track:51xHvAUYQfhY29GcGlBM0n",
        "name": "Piano Sonata No. 16 in C Major, K. 545 \"Sonata facile\": 1. Allegro",
        "imageUrl": "http://i.scdn.co/image/ab67616d0000b273bf4b533ee6e9634a6fcd8882",
        "album": {
          "uri": "spotify:album:1XORY4rQNhqkZxTze6Px90",
          "name": "Piano Book (Deluxe Edition)"
        },
        "artist": {
          "uri": "spotify:artist:4NJhFmfw43RLBLjQvxDuRS",
          "name": "Wolfgang Amadeus Mozart"
        },
        "context": {
          "uri": "spotify:user:spotify:playlist:37i9dQZF1E4riV8HyBkA7r",
          "name": "Wolfgang Amadeus Mozart Radio",
          "index": 0
        }
      }
    }
  ]
}

sp_dc cookie

This is the only value that you need for this to work. After you login on the web player (which I don't automate because reCAPTCHA), you get a bunch of cookies, including one named sp_dc.

Seems like it's valid for one year, and with just that value you can call anytime an endpoint that gives you a refreshed, elevated API access token, that, unlike the official API ones, will let you query the undocumented endpoint that retrieves the friend activity.

Usage with spotify-web-api-node

You might already be using the spotify-web-api-node package to use the official API.

To authenticate using the sp_dc cookie:

const SpotifyWebApi = require('spotify-web-api-node')
const buddyList = require('spotify-buddylist')

const api = new SpotifyWebApi()

const tokenResponse = await buddyList.getWebAccessToken(config.spotify.spDcCookie)

api.setAccessToken(tokenResponse.accessToken)

Should your script run more than the token response's accessTokenExpirationTimestampMs (currently an hour), I would suggest implementing token refresh logic which is just calling getWebAccessToken and setAccessToken again like above.

Don't know how to code?

If the documentation above doesn't make much sense to you, here's a couple extra information you might find useful. 🙏

Because spotify-buddylist is a library, it's meant to be used by other programs, and it doesn't makes any assumption on how it's going to be used. You're free to code a program that automatically populates another playlist, sends you a notification when a specific friend plays a specific song, feeds an online spreadsheet, or just appends to a local file.

But don't worry, if you don't know how to code, you can still use the example that just displays the data when you run it. The following steps will show you how to do that.

Installing

Because this library is built with Node.js, you'll need to install it first.

Then, download the archive for this repository and extract it.

Open a terminal, go in the spotify-buddylist directory that you just extracted, and run:

npm install

This will install the extra dependencies needed for the program to run.

Fetching the cookie

Then you'll need to grab your sp_dc cookie from Spotify. This is a requirement because Spotify doesn't allow third-party apps to get the friend activity feed, so this cookie allows us to pretend that we're the Spotify app itself to get access to that data.

For that, login on the web player and open your browser's web developer tools. It's usually in "settings", "more tools", "developer tools". In that pane, go in "application", "storage", "cookies", https://open.spotify.com (or something close to that depending on your browser).

You'll find a cookie named sp_dc. Copy its value.

Running the example

In the spotify-buddylist directory, open example.js with any text editor, and paste the cookie value in place of the text "put your cookie here".

Now, you can run the following command to execute the script:

node example.js

This will display the JSON response from Spotify (once).

If you want to run it periodically, you can uncomment the last line of the file (remove the // from the beginning of the line and save the file) and run the above command again. Now the script will run indefinitely, fetching new data every minute and appending it to the terminal output.

That should be enough to get you started! 🎉

If you want to do more things with that, you might want to learn a little bit of JavaScript. Programming is powerful, and will allow you to do the things that you want to do with your computer, instead of being limited to the things that someone else decided that you should be able to do. Enjoy!