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

0.7.2 • Public • Published

Spotify Web SDK

A JavaScript SDK for the Spotify Web API. Note that this project is still a BETA version.

Table of Contents

Features

"Why should I use this?"

We want to handle the hard work for you. Even to make simple requests, such as to get information on a track, you'd need to make a bunch of setups. Here is how you could do the same thing with our aid:

import * as spotify from 'spotify-web-sdk';
spotify.init({ token: 'YOUR SPOTIFY TOKEN HERE!' }); // You should only need to run this once.
spotify.getTrack('3LOpHuEpjkL4T1Zcjhko8w'); // Or any other track id.

Yes, it's as simple as that!

"I still think it's no hard work at all. Therefore, I don't see the point in using this."

How rude! As you might have noticed, this is an open source project, which means that you can add or suggest your own features. Of course, don't expect us to ever have a method such as getTaylorSwiftBestTracks pushed into our master branch. (But if you ever thought on something like that, hey, let's be friends!)

What we really mean is: there's a lot of information that can be extracted from the data retrievable via Spotify's Web API. If you think of something that could come in handy for you and also other people, that's it! Don't be shy, make it happen. We'll gladly review your suggestion as soon as possible!

For instance, you can retrieve the duration of a track in milliseconds straight from the API, but know what'd more usual? If you thought "displaying it in minutes", we're on the same page. To do that, adding the following code to our Track model would do the trick:

get formattedDuration() {
    const minutes = Math.floor(this.durationMs / 60000);
    const seconds = Math.floor((this.durationMs % 60000) / 1000);
    return `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
}

This is already implemented, but do you get our point? It might be something really simple, but we believe that such little things can save a lot of time in the future.

"You convinced me. Let's go!"

Even though I'm not certain you thought that right now, here's how to get started:

Installation

Using Yarn:

yarn add spotify-web-sdk

Using NPM:

npm install spotify-web-sdk

Using CDN:

<script src="https://unpkg.com/spotify-web-sdk/build/dist/spotify-web-sdk.min.js"></script>

Usage

First of all, you will need a Spotify authorization token. For that, check Spotify Web API's Authorization Guide. Please note that you might need some specific authorization scopes depending on the requests you'll be running.

And then you'll only need to import the function that implements the request you want to make. Remember that you'll need to run the init function passing your authorization token to authorize making the requests. There's an example of the usage at the beginning of this README.

Community

As aforementioned, this project exists because we believe that we can support each other to create a better experience for everyone. You can contribute in many ways. Please, note that we have a Code of Conduct, which we expect to be strictly respected.

Suggest a new feature or report a bug

If you notice any other bugs or you have any ideas to improve our SDK, feel free to create an issue. We'll be more than happy to discuss it! Check our issue templates.

Do it yourself

Check out our CONTRIBUTING file!

Maintainers

@JoseRenan and @JRobsonJr

Hall of Fame

Made with hall-of-fame.

License

MIT

Package Sidebar

Install

npm i spotify-web-sdk

Weekly Downloads

9

Version

0.7.2

License

MIT

Unpacked Size

1.86 MB

Total Files

115

Last publish

Collaborators

  • joserenan
  • jrobsonjr