Method: RSpotify.authenticate

Defined in:
lib/rspotify/connection.rb

.authenticate(client_id, client_secret) ⇒ Object

Authenticates access to restricted data. Requires user credentials

Examples:

RSpotify.authenticate("<your_client_id>", "<your_client_secret>")

playlist = RSpotify::Playlist.find('wizzler', '00wHcTN0zQiun4xri9pmvX')
playlist.name #=> "Movie Soundtrack Masterpieces"

Parameters:

  • client_id (String)
  • client_secret (String)


28
29
30
31
32
33
34
# File 'lib/rspotify/connection.rb', line 28

def authenticate(client_id, client_secret)
  @client_id, @client_secret = client_id, client_secret
  request_body = { grant_type: 'client_credentials' }
  response = RestClient.post(TOKEN_URI, request_body, auth_header)
  @client_token = JSON.parse(response)['access_token']
  true
end