Open fujisawaryohei opened 6 years ago
I do not know why the error like the one below appears. . "undefined method` encoding 'for nil: NilClass " I wrote as below.
def search_track(track_name) client_id = "CLIENT_ID" client_secret = "CLIENT_SECRET" tracks = RSpotify::Tracks.search(track_name,limit:20,market:"JP") array = [] tracks.each do |track| track_hash = {} track_hash['artist_name'] = track.artists.first.name track_hash['name'] = track.name track_hash['preview'] = track.preview_url track_hash['image'] = track.album.images[1]['url'] array.push(track_hash) puts array return array end
Please tell me the cause. .
I do not know why the error like the one below appears. . "undefined method` encoding 'for nil: NilClass " I wrote as below.
def search_track(track_name) client_id = "CLIENT_ID" client_secret = "CLIENT_SECRET" tracks = RSpotify::Tracks.search(track_name,limit:20,market:"JP") array = [] tracks.each do |track| track_hash = {} track_hash['artist_name'] = track.artists.first.name track_hash['name'] = track.name track_hash['preview'] = track.preview_url track_hash['image'] = track.album.images[1]['url'] array.push(track_hash) puts array return array end
Please tell me the cause. .