【问题标题】:Rails how to get SoundCloud track information using SoundCloud song URLRails 如何使用 SoundCloud 歌曲 URL 获取 SoundCloud 曲目信息
【发布时间】:2016-06-03 09:33:54
【问题描述】:

在我的 rails 项目中,我想使用用户从其 SoundCloud 帐户或任何 SoundCloud 链接提供的歌曲 URL 获取 SoundCloud 曲目/歌曲标题、描述、提供者数据。

【问题讨论】:

    标签: ruby-on-rails soundcloud


    【解决方案1】:

    您可以为此使用SoundCloud API - 请参阅SoundCloud URLs 部分:

    如果您有指向特定资源的永久链接 URL,但需要更多信息,例如 ID 或其他属性。在这些情况下,您可以使用/resolve 端点来提取资源的完整表示。

    还有一个使用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
    

    【讨论】:

    • 我只有 track_url,没有 client_id。我试图检索如下:client = SoundCloud.new(:access_token => my_access_token) track = client.get('/resolve', :url =>链接)引发track.inspect,错误是:HTTP状态:401未经授权
    • 您有自己的client_id,您可以通过它使用API​​。您必须“注册一个新应用程序”,它链接在 API 文档右侧的菜单中。如果您从client.exchange_token 检索到有效的:access_token,则可能就足够了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-21
    • 1970-01-01
    相关资源
    最近更新 更多