How to use spotify-web-api-node - 7 common examples

To help you get started, we’ve selected a few spotify-web-api-node examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jemise111 / dj-lazy / src / index.js View on Github external
scopes       : ['playlist-modify-public', 'playlist-modify-private'],
	redirectPath : '/spotify-auth',
	port         : 8085
};

const clientId = process.env.DJ_LAZY_CLIENT_ID;
const clientSecret = process.env.DJ_LAZY_CLIENT_SECRET;
const redirectUri = `http://localhost:${config.port}${config.redirectPath}`;

if (!clientId || !clientSecret) {
	const err = new Error('Missing cliendId or clientSecret\nEnsure you have DJ_LAZY_CLIENT_ID and DJ_LAZY_CLIENT_SECRET set as ENV variables');
	throw err;
}

// Create Spotify API wrapper
const spotifyApi = new SpotifyWebApi({clientId, clientSecret, redirectUri});

// Create the authorization URL
const authorizeURL = spotifyApi.createAuthorizeURL(config.scopes, 'mystate');

const app = express();
let server;

app.get(config.redirectPath, (req, res) => {
	const authToken = req.query.code;
	res.send('');
	server.close();
	startScraping(authToken);
});

server = app.listen(config.port, _ => console.log(`Server listening on port ${config.port}!\n`) );
open(authorizeURL);
github kudos / combine.fm / lib / services / spotify / index.js View on Github external
import { parse } from 'url';
import SpotifyWebApi from 'spotify-web-api-node';
import urlMatch from './url';

const spotify = new SpotifyWebApi({
  clientId: process.env.SPOTIFY_CLIENT_ID,
  clientSecret: process.env.SPOTIFY_CLIENT_SECRET,
  redirectUri: 'https://combine.fm',
});


function exactMatch(needle, haystack, type) {
  // try to find exact match
  return haystack.find((entry) => {
    if (entry.type !== type) {
      return false;
    }

    if (entry.name === needle) {
      return entry;
    }
github sogehige / sogeBot / src / bot / integrations / spotify.ts View on Github external
try {
      const err: string[] = [];
      if (this.clientId.trim().length === 0) {
        err.push('clientId');
      }
      if (this.clientSecret.trim().length === 0) {
        err.push('clientSecret');
      }
      if (this.redirectURI.trim().length === 0) {
        err.push('redirectURI');
      }
      if (err.length > 0) {
        throw new Error(err.join(', ') + ' missing');
      }

      this.client = new SpotifyWebApi({
        clientId: this.clientId,
        clientSecret: this.clientSecret,
        redirectUri: this.redirectURI,
      });

      if (this._accessToken && this._refreshToken) {
        this.client.setAccessToken(this._accessToken);
        this.client.setRefreshToken(this._refreshToken);
        this.retry.IRefreshToken = 0;
      }

      try {
        if (opts.token && !_.isNil(this.client)) {
          this.client.authorizationCodeGrant(opts.token)
            .then((data) => {
              this.authenticatedScopes = data.body.scope.split(' ');
github DalerAsrorov / componofy / api / spotify.js View on Github external
import SpotifyWebApi from 'spotify-web-api-node';
import * as R from 'ramda';
import fetch from 'node-fetch';
import dotenv from 'dotenv';

dotenv.config();

const DEV_HOST = 'http://localhost:3000';
const SCOPES_STR =
  'user-library-read playlist-read-private playlist-read-collaborative playlist-modif' +
  'y-public playlist-modify-private user-library-read ugc-image-upload user-top-read';
const SCOPE_LIST = SCOPES_STR.split(' ');
const SPOTIFY_API_URL = 'https://api.spotify.com/v1';
const spotifyApi = new SpotifyWebApi({
  clientId: process.env.SPOTIFY_CLIENT,
  clientSecret: process.env.SPOTIFY_CLIENT_SECRET,
  redirectUri: process.env.SPOTIFY_REDIRECT_URI
});
const { APP_CLIENT_URL } = process.env;
const INTERVAL_PERIOD = 5000;

let userMap = {};

const setUpTokens = (accessToken, refreshToken) => {
  spotifyApi.setAccessToken(accessToken);
  spotifyApi.setRefreshToken(refreshToken);
};

export const setUserAndTokens = (userId, accessToken, refreshToken) => {
  userMap[userId] = {
github brian-ai / core / src / services / spotify / index.js View on Github external
const loadBrianfy = async (access, refresh) => {
	const Brianfy = new SpotifyWebApi()
	Brianfy.setAccessToken(access)
	Brianfy.setRefreshToken(refresh)

	return Brianfy
}
github ItsWendell / google-assistant-desktop-client / src / renderer / providers / spotify / spotify.js View on Github external
constructor() {
		super();
		this.spotifyClient = new SpotifyAPIClient({
			clientId: config.spotify.clientId,
			clientSecret: config.spotify.clientSecret,
			redirectUri: config.spotify.redirectUri,
		});
		this.scopes = config.spotify.scopes;
	}
github chienkira / musyc / src / index.js View on Github external
import SpotifyWebApi from 'spotify-web-api-node';
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import configureStore from './stores/configureStore';
import Root from './components/Root';
import App from './components/App';
import * as AUTH from './constants/auth';

const isDevelopmentEnv = (process.env.NODE_ENV !== 'production')
window.spotifyApi = new SpotifyWebApi({
  clientId: isDevelopmentEnv ? AUTH.CLIENT_ID_DEV : AUTH.CLIENT_ID_PROD,
  redirectUri: isDevelopmentEnv ? AUTH.REDIRECT_URI_DEV : AUTH.REDIRECT_URI_PROD
})

const store = configureStore()

ReactDOM.render(
  
    
      
    
  ,
  document.getElementById('app')
)

spotify-web-api-node

A Node.js wrapper for Spotify's Web API

MIT
Latest version published 4 years ago

Package Health Score

59 / 100
Full package analysis

Popular spotify-web-api-node functions