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

light-spotify

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

light-spotify

A Spotify wrapper that makes it easy to work with Spotify's api.

  • 1.1.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

What is light-spotify?

light-spotify is a Spotify wrapper to make it easy to work with Spotify's API.

Installation

For npm: npm i light-spotify

For yarn: yarn add light-spotify

Usage

Its important to make sure that you have a valid access token to make requests. To make an access token, you can use the simple code below.

const baseUrl = "https://accounts.spotify.com/api/token";
  const getData = await fetch(baseUrl, {
    method: "POST",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
      Authorization:
        "Basic " +
        new Buffer.from(`${CLIENT_ID}:${CLIENT_SECRET}`).toString("base64"),
    },
    body: "grant_type=client_credentials",
  })
  .then(res => res.json())
  .then(data => {
console.log(data)
/*{
  access_token: 'GENERATED ACCESS TOKEN',
  token_type: 'Bearer',
  expires_in: 3600
}*/.
})

Then, create a new instance of the package.

import { LightSpotify } from 'light-spotify';
const SpotifyAPI = new LightSpotify();

//set access token here.
SpotifyAPI.setAccessToken = 'ACCESS_TOKEN';

//if you ever need to get the access token.
console.log(Spotify.getAccessToken); //returns the token.

Requests

Making requests with light-spotify is easy. Want to get multiple albums? Easy.

const { LightSpotify } = require("light-spotify");
const spotify = new LightSpotify();
const albumIds = ['ID1', 'ID2', 'ID3']; // max 20 ids;
//set the access token first.
spotify.setAccessToken = 'asd'; // get the auth token;
//param 1: token || param 2: the album id or album ids || param 3: the market (valid ISO 3161 code).
spotify
	.getMultipleAlbums(spotify.getAccessToken, albumIds, 'US') // returns Promise of AxiosResponse
	//Handle the resolved promise.
	.then((i) => {
		console.log(i.data);
	})
	//handle errors
	.catch(console.error);

Oh yeah. And we also have full Typescript support. :)

Check out /docs/TOC.md for all data requests that you can make.

Contributions

Any contributions are welcome. Check out CONTRIBUTING.md for more info.

FAQs

Package last updated on 21 Apr 2021

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