Rails how to get SoundCloud track information using SoundCloud song URL

ε祈祈猫儿з 提交于 2019-12-02 06:12:58

问题


In my rails project, I want to get SoundCloud track/song title, description, provider data using song url given by user from his SoundCloud account or any SoundCloud link.


回答1:


You can use the SoundCloud API for this - see section SoundCloud URLs:

If you have a permalink URL to a particular resource, but need more information such as an ID or other property. In these cases, you can use the /resolve endpoint to extract a full representation of the resource.

There's also an example using Ruby:

require 'soundcloud'

# create client with your app's credentials
client = Soundcloud.new(:client_id => 'YOUR_CLIENT_ID')

# a permalink to a track
track_url = 'http://soundcloud.com/forss/voca-nomen-tuum'

# resolve track URL into track resource
track = client.get('/resolve', :url => track_url)

# now that we have the track id, we can get a list of comments, for example
client.get("/tracks/#{track.id}/comments").each do |comment|
  puts "Someone said: #{comment.body} at #{comment.timestamp}"
end


来源:https://stackoverflow.com/questions/37610812/rails-how-to-get-soundcloud-track-information-using-soundcloud-song-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!