Rails how to get SoundCloud track information using SoundCloud song URL

后端 未结 1 1104
一生所求
一生所求 2021-01-23 03: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条回答
  • 2021-01-23 04:11

    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
    
    0 讨论(0)
提交回复
热议问题