1.0.2 • Published 3 years ago

spotifylib.js v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

spotifylib.js

node.js lib based on Spotify's web api - covering all you will need. Easily fetching data about: tracks, albums, artists and even able to pause, resume and start different playbacks.

Authorization

First thing to do when authorizating your spotify app you need to use get your code which will later be used to request an access token. Using #generate you are able to concat a callback uri to obtain your Spotify code. Example seen here

const express = require('express');
const app = express();

const { SpotifyClient } = require('spotifylib.js'); const client = new SpotifyClient({ client_id: 'CLIENT ID', client_secret: 'CLIENT SECRET', redirect_uri: 'http://localhost:3000/callback' // The redirect uri });

app.get('/login', (req, res) => { let uri = client.authorization.generate(); res.redirect(uri); });

After this you will need to exchange the code for a access token using `#exchange(code)` - these tokens expire every hour which means you get a refresh token along with it, which is used to refresh the token every expiry.
```js
app.get('/callback', async (req, res) => {
	let code = req.query.code;
	let tokens =  await client.authorization.exchange(code);
	res.send(tokens);
});

Once the refresh token is obtained it must be put into the SpotifyClient options when initiated as refresh_token then you can start requesting data from Spotify's web api.

View the documenation here for more info.

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago