Rails 如何使用 SoundCloud 歌曲 URL 获取 SoundCloud 曲目信息 [英] Rails how to get SoundCloud track information using SoundCloud song URL
问题描述
在我的 rails 项目中,我想使用用户从他的 SoundCloud 帐户或任何 SoundCloud 链接提供的歌曲 url 获取 SoundCloud 曲目/歌曲标题、描述、提供者数据.
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.
推荐答案
您可以使用 SoundCloud API 为此 - 请参阅 SoundCloud URL 部分:
You can use the SoundCloud API for this - see section SoundCloud URLs:
如果您有指向特定资源的固定链接 URL,但需要更多信息,例如 ID 或其他属性.在这些情况下,您可以使用 /resolve 端点来提取资源.
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.
还有一个使用 Ruby 的例子:
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
这篇关于Rails 如何使用 SoundCloud 歌曲 URL 获取 SoundCloud 曲目信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!