Answer the question
In order to leave comments, you need to log in
How to work with Spotify API via Ruby ( RestClient, Watir...)?
Hello,
I need to connect via ruby and take a token from spotify (What I did),
but the token that they send me is low-level (from Flow'a client_credentials), and when I change Flow'a, I get a BAD REQUEST.
Token request:
grant = Base64.encode64("#{CLIENT_ID}:#{CLIENT_SECRET}").delete("\n")
respond = RestClient.post('https://accounts.spotify.com/api/token',
{'grant_type' => 'client_credentials'},
{"Authorization" => "Basic #{grant}"})
token_ext = respond.split(',')
token_ext2 = token_ext[0].split(':')
only_token = token_ext2[1].delete_prefix('"').delete_suffix('"')
puts 'ACCES TOKEN: %s' % [only_token]
# respond = RestClient.post('https://api.spotify.com/v1/users/%s/playlists' % [USER_ID],
# {"Content-Type" => "application/json"},
# {"Authorization" => "Basic #{grant}"})
# respond = RestClient.post('https://api.spotify.com/v1/users/%s/playlists' % [USER_ID],
#
# {"Content-Type" => "application/json"},
# {"Authorization" => "Basic #{grant}"},
# ) { "name" => "New Playlilist" ; "description" => "sdada" ; "public" => "false"}
config = {
:access_token => only_token.to_s, # initialize the client with an access token to perform authenticated calls
:raise_errors => true, # choose between returning false or raising a proper exception when API calls fails
# Connection properties
:retries => 1, # automatically retry a certain number of times before returning
:read_timeout => 10, # set longer read_timeout, default is 10 seconds
:write_timeout => 10, # set longer write_timeout, default is 10 seconds
:persistent => false # when true, make multiple requests calls using a single persistent connection. Use +close_connection+ method on the client to manually clean up sockets
}
client = Spotify::Client.new(config)
sleep(2)
puts client.create_user_playlist(USER_ID, "ALOHA", is_public = true)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question