Giter VIP home page Giter VIP logo

spotifyr's Introduction

spotifyr: a wrapper for Spotify's API for R users

spotifyr is currently undergoing active testing and improvement.

It currently launches Firefox through RSelenium for the full authorization code flow. Chrome and IE will eventually be supported, but are not yet. All data from endpoints is converted to lists. If you just want access to the public endpoints, this is not necessary.

Some of the objects (artists, albums, playlists) have helper functions to conver to data.frame, but not all yet, and this is the next major development plan.

Installation

Requires Firefox for initial authentication for any of the endpoints that operate on user data.

devtools::install_github('rweyant/spotifyr')

Authentication

For any usage below, you'll need to have proper credentials from Spotify. Sign up for an account here and create an app.

# First Step: make client_id and client_secret available to other function
set_credentials(client_id=YOUR_CLIENT_ID,client_secret=YOUR_CLIENT_SECRET)

Authenticate with Client Credentials

client_tokens <- get_tokens()

Authenticate with Authorization Code

# Opens Browser window asking for permission to access data
# Requires Spotify account and for user to login
user_code <- get_user_code()

# Assigns tokens for later use.
# This creates a variable access_token in the Global Environment 
# that all future functions will access.
user_tokens <- get_user_token(user_code)

# If your access_token expires and you need to refresh your tokens 
# With no parameters specified, looks for refresh_token in the Global Environment
refresh_tokens <- refresh_user_token()

# If you want, you can explicitly specify the refresh token
refresh_tokens <- refresh_user_token(user_tokens$refresh_token)

Basic Usage

Search for Data

Get information, identifiers, images, etc. for artists, albums, songs or playlists that match the query text. No authentication is required for this function.


# Search for an artist
search('slayer',type='artist')

# Get top search result
search('slayer',type='artist',limit=1)

# Search for an album
search('South Of Heaven',type='album')

Get Information About Artist

Search for an artist by Spotify ID and get information about band, genre, images, etc. No authentication is required for this function.

get_artist('1IQ2e1buppatiN1bxUVkrk')

# Get all albums by Slayer on Spotify
get_artist_albums('1IQ2e1buppatiN1bxUVkrk')

# Get top tracks of Slayer in the US. Country code required.
get_artist_toptracks('1IQ2e1buppatiN1bxUVkrk','US')

# Get related artists according to Spotify in list 
get_artist_relatedartists('1IQ2e1buppatiN1bxUVkrk')

# Get related artists according to Spotify and simplify to a data.frame
simplify_result(get_artist_relatedartists('1IQ2e1buppatiN1bxUVkrk'),type='artists')

Access Library information

There are endpoints to access and modify data in user's library

# Get the last 2 tracks saved by the user.
get_saved_tracks(limit=2)

Followers

Get information about what artists a user is following, add/remove followers from user, check if a user is following someone

# Get list of all artists a user is following
get_user_followed_artists()

# Check if my account is being followed.
following('rweyant',type='user')

# Follow my account
follow('rweyant',type='user')

# Check if Slayer is being followed.  Use Spotify Artist ID
following('1IQ2e1buppatiN1bxUVkrk',type='artist')

# Follow Slayer
follow('1IQ2e1buppatiN1bxUVkrk',type='artist')

User Profile Data

# Specific user's data
get_user_profile('rweyant')

# Get the user who is using the application
get_current_user_profile()

More Resources

spotifyr's People

Contributors

rweyant avatar

Watchers

Buel Chandler 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.