Git Product home page Git Product logo

spotify-player's Introduction

Spotify Player

A node.js server plus a light JS library to create integrations with the Spotify Web API Connect endpoints.

Using the library

Import the script https://spotify-player.herokuapp.com/spotify-player.js. Now you can log the user in and listen to updates on playback:

var spotifyPlayer = new SpotifyPlayer();

spotifyPlayer.on('update', response => {
  // response is a json object obtained as a response of
  // https://developer.spotify.com/web-api/get-information-about-the-users-current-playback/
});

spotifyPlayer.on('login', user => {
  if (user === null) {
    // there is no user logged in or the user was logged out
  } else {
    // the user is logged in
    // user is a json object obtained as a response of
    // https://developer.spotify.com/web-api/get-current-users-profile/
  }
});

loginButton.addEventListener('click', () => {
    spotifyPlayer.login();
});

logoutButton.addEventListener('click', () => {
    spotifyPlayer.logout();
});

spotifyPlayer.init();

Have a look at http://codepen.io/jmperez/pen/MmwObE for an example of a visualization using this library.

The library uses a shared server to issue the initial access token and refreshed tokens. This means your integration could reach Spotify's rate limits easily. If you want to have more control on this, deploy the code to your own server using the following instructions.

Server

The server can be run locally and also deployed to Heroku. You will need to register your own Spotify app and pass the credentials to the server. For that:

  1. Create an application on Spotify's Developer Site.
  2. Add as redirect uris both http://localhost:5000/callback (for development) and <production_domain>/callback (if you want to deploy your app somewhere)
  3. Keep the client ID and client secret somewhere. You'll need them next.

Running Locally

Make sure you have Node.js.

$ npm install
$ CLIENT_ID=<your_client_id> CLIENT_SECRET=<your_client_secret> REDIRECT_URI=<your_redirect_uri> npm start

Your app should now be running on localhost:5000.

Deploying to Heroku

You will need to have the Heroku CLI installed.

$ heroku create
$ git push heroku master
$ heroku open

or

Deploy to Heroku

You will then need to set the environment variables using heroku config:set:

$ heroku config:set CLIENT_ID=<your_client_id>
$ heroku config:set CLIENT_SECRET=<your_client_secret>
$ heroku config:set REDIRECT_URI=<your_redirect_uri>

spotify-player's People

Contributors

jmperez avatar iivoix avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.